@sweepbright/api-client 0.30.2 → 0.30.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +102 -0
- package/.devcontainer/Dockerfile +23 -0
- package/.devcontainer/devcontainer.json +59 -0
- package/.editorconfig +11 -0
- package/.eslintrc.json +6 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +40 -0
- package/.nvmrc +1 -0
- package/.prettierignore +1 -0
- package/jest.config.js +7 -0
- package/mockServer.ts +44 -0
- package/package.json +3 -6
- package/setupTests.ts +1 -0
- package/src/__tests__/auth.test.ts +14 -0
- package/src/__tests__/channels.test.ts +104 -0
- package/src/__tests__/contacts.test.ts +85 -0
- package/src/__tests__/estates.test.ts +50 -0
- package/src/__tests__/leads.test.ts +67 -0
- package/src/common/currencies.ts +50 -0
- package/src/common/types.ts +1 -0
- package/src/entities/office.ts +193 -0
- package/src/entities/property.ts +574 -0
- package/src/index.ts +128 -0
- package/src/resources/channel_accounts.ts +39 -0
- package/src/resources/channels.ts +52 -0
- package/src/resources/companies.ts +15 -0
- package/src/resources/contact_preferences.ts +14 -0
- package/src/resources/contacts.ts +38 -0
- package/src/resources/estates.ts +145 -0
- package/src/resources/leads.ts +65 -0
- package/src/resources/negotiators.ts +19 -0
- package/src/resources/offices.ts +12 -0
- package/src/types.ts +88 -0
- package/src/utils.ts +35 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
version: 2.1
|
|
2
|
+
|
|
3
|
+
executors:
|
|
4
|
+
node:
|
|
5
|
+
docker:
|
|
6
|
+
- image: cimg/node:16.15.0
|
|
7
|
+
|
|
8
|
+
x-definitions:
|
|
9
|
+
- &filters-only-tags
|
|
10
|
+
branches:
|
|
11
|
+
ignore: /.*/
|
|
12
|
+
tags:
|
|
13
|
+
only: /^v.*/
|
|
14
|
+
- &filters-any
|
|
15
|
+
branches:
|
|
16
|
+
only: /.*/
|
|
17
|
+
tags:
|
|
18
|
+
only: /^v.*/
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
|
|
22
|
+
build:
|
|
23
|
+
executor: node
|
|
24
|
+
steps:
|
|
25
|
+
- checkout
|
|
26
|
+
- restore_cache:
|
|
27
|
+
keys:
|
|
28
|
+
- yarn-v1-{{ checksum "yarn.lock" }}
|
|
29
|
+
- yarn-v1-
|
|
30
|
+
- run:
|
|
31
|
+
name: Authenticate with registry
|
|
32
|
+
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
|
|
33
|
+
- run: yarn install
|
|
34
|
+
- save_cache:
|
|
35
|
+
key: yarn-v1-{{ checksum "yarn.lock" }}
|
|
36
|
+
paths:
|
|
37
|
+
- node_modules
|
|
38
|
+
- persist_to_workspace:
|
|
39
|
+
root: ~/project
|
|
40
|
+
paths:
|
|
41
|
+
- .
|
|
42
|
+
- run: yarn build
|
|
43
|
+
- run:
|
|
44
|
+
name: List build artifacts
|
|
45
|
+
command: ls -al ~/project/dist
|
|
46
|
+
|
|
47
|
+
lint:
|
|
48
|
+
executor: node
|
|
49
|
+
steps:
|
|
50
|
+
- attach_workspace:
|
|
51
|
+
at: ~/project
|
|
52
|
+
- run: yarn lint
|
|
53
|
+
|
|
54
|
+
test:
|
|
55
|
+
executor: node
|
|
56
|
+
steps:
|
|
57
|
+
- attach_workspace:
|
|
58
|
+
at: ~/project
|
|
59
|
+
- run: yarn test
|
|
60
|
+
|
|
61
|
+
deploy:
|
|
62
|
+
executor: node
|
|
63
|
+
steps:
|
|
64
|
+
- attach_workspace:
|
|
65
|
+
at: ~/project
|
|
66
|
+
- run:
|
|
67
|
+
name: Authenticate with registry
|
|
68
|
+
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
|
|
69
|
+
- run:
|
|
70
|
+
name: List build artifacts
|
|
71
|
+
command: ls -al ~/project
|
|
72
|
+
- run:
|
|
73
|
+
name: Publish package
|
|
74
|
+
command: yarn publish
|
|
75
|
+
|
|
76
|
+
workflows:
|
|
77
|
+
version: 2
|
|
78
|
+
test-deploy:
|
|
79
|
+
jobs:
|
|
80
|
+
- build:
|
|
81
|
+
context: npm-context
|
|
82
|
+
filters: *filters-any
|
|
83
|
+
- lint:
|
|
84
|
+
context: npm-context
|
|
85
|
+
filters: *filters-any
|
|
86
|
+
requires:
|
|
87
|
+
- build
|
|
88
|
+
- test:
|
|
89
|
+
context: npm-context
|
|
90
|
+
filters: *filters-any
|
|
91
|
+
requires:
|
|
92
|
+
- lint
|
|
93
|
+
- approve:
|
|
94
|
+
name: approve
|
|
95
|
+
type: approval
|
|
96
|
+
filters: *filters-any
|
|
97
|
+
- deploy:
|
|
98
|
+
context: npm-publish
|
|
99
|
+
requires:
|
|
100
|
+
- test
|
|
101
|
+
- approve
|
|
102
|
+
filters: *filters-any
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.202.5/containers/typescript-node/.devcontainer/base.Dockerfile
|
|
2
|
+
|
|
3
|
+
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
|
|
4
|
+
ARG VARIANT="14-bullseye"
|
|
5
|
+
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
|
|
6
|
+
|
|
7
|
+
# Add repository for GitHub CLI
|
|
8
|
+
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg \
|
|
9
|
+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
|
|
10
|
+
|
|
11
|
+
# [Optional] Uncomment this section to install additional OS packages.
|
|
12
|
+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
|
13
|
+
&& apt-get -y install --no-install-recommends python2 htop mc gh
|
|
14
|
+
|
|
15
|
+
# Install Phrase client binary
|
|
16
|
+
RUN wget https://github.com/phrase/phrase-cli/releases/download/2.3.0/phrase_linux_amd64 -O /usr/bin/phrase && chmod a+x /usr/bin/phrase
|
|
17
|
+
|
|
18
|
+
# [Optional] Uncomment if you want to install an additional version of node using nvm
|
|
19
|
+
# ARG EXTRA_NODE_VERSION=10
|
|
20
|
+
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
|
|
21
|
+
|
|
22
|
+
# [Optional] Uncomment if you want to install more global node packages
|
|
23
|
+
# RUN su node -c "npm install -g <your-package-list -here>"
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
|
2
|
+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.202.5/containers/typescript-node
|
|
3
|
+
{
|
|
4
|
+
"name": "Node.js & TypeScript",
|
|
5
|
+
"runArgs": [
|
|
6
|
+
"--init"
|
|
7
|
+
],
|
|
8
|
+
"build": {
|
|
9
|
+
"dockerfile": "Dockerfile",
|
|
10
|
+
// Update 'VARIANT' to pick a Node version: 16, 14, 12.
|
|
11
|
+
// Append -bullseye or -buster to pin to an OS version.
|
|
12
|
+
// Use -bullseye variants on local on arm64/Apple Silicon.
|
|
13
|
+
"args": {
|
|
14
|
+
"VARIANT": "14-bullseye"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
// Set *default* container specific settings.json values on container create.
|
|
18
|
+
"settings": {},
|
|
19
|
+
// Add the IDs of extensions you want installed when the container is created.
|
|
20
|
+
"mounts": [
|
|
21
|
+
//For deploying with Serverless
|
|
22
|
+
"source=${localEnv:HOME}/.aws,target=/home/node/.aws,type=bind,consistency=cached"
|
|
23
|
+
],
|
|
24
|
+
"extensions": [
|
|
25
|
+
"dbaeumer.vscode-eslint",
|
|
26
|
+
"maptz.regionfolder",
|
|
27
|
+
"wmaurer.change-case",
|
|
28
|
+
"jvandyke.vscode-circleci",
|
|
29
|
+
"anseki.vscode-color",
|
|
30
|
+
"nemesv.copy-file-name",
|
|
31
|
+
"ryanluker.vscode-coverage-gutters",
|
|
32
|
+
"aeschli.vscode-css-formatter",
|
|
33
|
+
"jpruliere.env-autocomplete",
|
|
34
|
+
"waderyan.gitblame",
|
|
35
|
+
"github.vscode-pull-request-github",
|
|
36
|
+
"eamodio.gitlens",
|
|
37
|
+
"pushqrdx.inline-html",
|
|
38
|
+
"orta.vscode-jest",
|
|
39
|
+
"cmstead.js-codeformer",
|
|
40
|
+
"eg2.vscode-npm-script",
|
|
41
|
+
"silvenga.positions",
|
|
42
|
+
"esbenp.prettier-vscode",
|
|
43
|
+
"2gua.rainbow-brackets",
|
|
44
|
+
"unional.vscode-sort-package-json",
|
|
45
|
+
"hbenl.vscode-test-explorer"
|
|
46
|
+
],
|
|
47
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
|
48
|
+
"forwardPorts": [
|
|
49
|
+
3000,
|
|
50
|
+
3001
|
|
51
|
+
],
|
|
52
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
|
53
|
+
// "postCreateCommand": "yarn",
|
|
54
|
+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
|
55
|
+
"remoteUser": "node",
|
|
56
|
+
"containerEnv": {
|
|
57
|
+
"NPM_TOKEN": "${localEnv:NPM_TOKEN}"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/.editorconfig
ADDED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
### Add any information and/or comments that might be useful to your reviewer:
|
|
2
|
+
|
|
3
|
+
*For example: what is the current behaviour?*
|
|
4
|
+
|
|
5
|
+
*How has this change.*
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
### Please check the type of change your PR introduces:
|
|
9
|
+
- [ ] Bugfix
|
|
10
|
+
- [ ] Feature
|
|
11
|
+
- [ ] CI improvement
|
|
12
|
+
- [ ] Refactoring (no functional changes, no api changes)
|
|
13
|
+
- [ ] Build related changes
|
|
14
|
+
- [ ] Documentation content changes
|
|
15
|
+
- [ ] Other (please describe)
|
|
16
|
+
---
|
|
17
|
+
### Checklist before requesting a review:
|
|
18
|
+
- [ ] I have performed a self-review of my code
|
|
19
|
+
- [ ] I have improved the technical debt/and not created more
|
|
20
|
+
- [ ] I have increased test coverage.
|
|
21
|
+
- [ ] I have made corresponding changes to the documentation or created an issue for this.
|
|
22
|
+
- [ ] Changing documentation was not necessary - but I considered if it was important for this change.
|
|
23
|
+
---
|
|
24
|
+
### How has this been Tested?
|
|
25
|
+
- [ ] WebApp
|
|
26
|
+
- [ ] iOS
|
|
27
|
+
- [ ] Android
|
|
28
|
+
- [ ] Other - *need to comment*
|
|
29
|
+
|
|
30
|
+
*I tested this by...*
|
|
31
|
+
|
|
32
|
+
*going to...and typing/clicking...it can be reproduced by...*
|
|
33
|
+
|
|
34
|
+
*creating the unit tests...*
|
|
35
|
+
|
|
36
|
+
*see the images/video here that show...*
|
|
37
|
+
|
|
38
|
+
*I consider the edge cases...*
|
|
39
|
+
|
|
40
|
+
*I know my tests don't cover...*
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
16
|
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dist
|
package/jest.config.js
ADDED
package/mockServer.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { rest } from 'msw';
|
|
2
|
+
import { setupServer } from 'msw/node';
|
|
3
|
+
|
|
4
|
+
const server = setupServer(
|
|
5
|
+
rest.post('*', (req, res, ctx) => {
|
|
6
|
+
return res(
|
|
7
|
+
ctx.status(500),
|
|
8
|
+
ctx.json({ error: 'Mock this request ' + req.url.toString() })
|
|
9
|
+
);
|
|
10
|
+
}),
|
|
11
|
+
rest.get('*', (req, res, ctx) => {
|
|
12
|
+
return res(
|
|
13
|
+
ctx.status(500),
|
|
14
|
+
ctx.json({ error: 'Mock this request ' + req.url.toString() })
|
|
15
|
+
);
|
|
16
|
+
}),
|
|
17
|
+
rest.put('*', (req, res, ctx) => {
|
|
18
|
+
return res(
|
|
19
|
+
ctx.status(500),
|
|
20
|
+
ctx.json({ error: 'Mock this request ' + req.url.toString() })
|
|
21
|
+
);
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
beforeAll(() => server.listen());
|
|
26
|
+
afterAll(() => server.close());
|
|
27
|
+
beforeEach(() => server.resetHandlers());
|
|
28
|
+
|
|
29
|
+
const handlers = {
|
|
30
|
+
authHandler: rest.post(
|
|
31
|
+
'https://api.sweepbright.com/auth/access-token',
|
|
32
|
+
(_req, res, ctx) => {
|
|
33
|
+
return res(
|
|
34
|
+
ctx.status(200),
|
|
35
|
+
ctx.json({
|
|
36
|
+
access_token: 'FAKE_TOKEN',
|
|
37
|
+
expires_in: Date.now(),
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { server, rest, handlers };
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.30.
|
|
2
|
+
"version": "0.30.4",
|
|
3
3
|
"license": "UNLICENCED",
|
|
4
|
-
"main": "
|
|
5
|
-
"typings": "
|
|
6
|
-
"files": [
|
|
7
|
-
"dist"
|
|
8
|
-
],
|
|
4
|
+
"main": "/src/index.js",
|
|
5
|
+
"typings": "/src/types.js",
|
|
9
6
|
"scripts": {
|
|
10
7
|
"build": "yarn tsc",
|
|
11
8
|
"test": "yarn jest --forceExit --detectOpenHandles",
|
package/setupTests.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './mockServer';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createClient } from '../';
|
|
2
|
+
import { handlers, server } from '../../mockServer';
|
|
3
|
+
|
|
4
|
+
describe('authorization', () => {
|
|
5
|
+
it('can fetch an auth token', async () => {
|
|
6
|
+
const client = createClient({
|
|
7
|
+
clientId: 'FAKE_ID',
|
|
8
|
+
clientSecret: 'FAKE_SECRET',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
server.use(handlers.authHandler);
|
|
12
|
+
await client.authorize({});
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createClient } from '../';
|
|
2
|
+
import { handlers, rest, server } from '../../mockServer';
|
|
3
|
+
|
|
4
|
+
describe('channels', () => {
|
|
5
|
+
it('can fetch a references list', async () => {
|
|
6
|
+
const client = createClient({
|
|
7
|
+
clientId: 'FAKE_ID',
|
|
8
|
+
clientSecret: 'FAKE_SECRET',
|
|
9
|
+
});
|
|
10
|
+
server.use(handlers.authHandler);
|
|
11
|
+
await client.authorize();
|
|
12
|
+
|
|
13
|
+
const estateId = 'FAKE_ESTATE_ID';
|
|
14
|
+
const reference = 'FAKE_REFERENCE';
|
|
15
|
+
const channelAccountId = 'FAKE_CHANNEL_ACCOUNT_ID';
|
|
16
|
+
const companyId = 'FAKE_COMPANY_ID';
|
|
17
|
+
const channelId = 'FAKE_CHANNEL_ID';
|
|
18
|
+
|
|
19
|
+
server.use(
|
|
20
|
+
rest.get(
|
|
21
|
+
'https://api.sweepbright.com/services/channel-references',
|
|
22
|
+
(req, res, ctx) => {
|
|
23
|
+
return res(
|
|
24
|
+
ctx.status(200),
|
|
25
|
+
ctx.json({
|
|
26
|
+
data: [
|
|
27
|
+
{
|
|
28
|
+
reference_code: req.url.searchParams.get('reference_code'),
|
|
29
|
+
company_id: req.url.searchParams.get('company_id'),
|
|
30
|
+
channel_id: req.url.searchParams.get('channel_id'),
|
|
31
|
+
estate_id: estateId,
|
|
32
|
+
channel_account_id: channelAccountId,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const result = await client.channels.resolveReferences(
|
|
42
|
+
channelId,
|
|
43
|
+
reference,
|
|
44
|
+
companyId
|
|
45
|
+
);
|
|
46
|
+
expect(result).toEqual({
|
|
47
|
+
data: [
|
|
48
|
+
{
|
|
49
|
+
reference_code: reference,
|
|
50
|
+
estate_id: estateId,
|
|
51
|
+
channel_account_id: channelAccountId,
|
|
52
|
+
channel_id: channelId,
|
|
53
|
+
company_id: companyId,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('it does not send a company_id when not set', async () => {
|
|
60
|
+
const client = createClient({
|
|
61
|
+
clientId: 'FAKE_ID',
|
|
62
|
+
clientSecret: 'FAKE_SECRET',
|
|
63
|
+
});
|
|
64
|
+
server.use(handlers.authHandler);
|
|
65
|
+
await client.authorize();
|
|
66
|
+
|
|
67
|
+
const estateId = 'FAKE_ESTATE_ID';
|
|
68
|
+
const reference = 'FAKE_REFERENCE';
|
|
69
|
+
const channelAccountId = 'FAKE_CHANNEL_ACCOUNT_ID';
|
|
70
|
+
const channelId = 'FAKE_CHANNEL_ID';
|
|
71
|
+
|
|
72
|
+
server.use(
|
|
73
|
+
rest.get(
|
|
74
|
+
'https://api.sweepbright.com/services/channel-references',
|
|
75
|
+
(req, res, ctx) => {
|
|
76
|
+
try {
|
|
77
|
+
expect(req.url.search).toEqual(
|
|
78
|
+
`?channel_id=${channelId}&reference_code=${reference}`
|
|
79
|
+
);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
return res(ctx.status(500), ctx.json({ error: e }));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return res(
|
|
85
|
+
ctx.status(200),
|
|
86
|
+
ctx.json({
|
|
87
|
+
data: [
|
|
88
|
+
{
|
|
89
|
+
reference_code: req.url.searchParams.get('reference_code'),
|
|
90
|
+
company_id: 'FAKE',
|
|
91
|
+
channel_id: req.url.searchParams.get('channel_id'),
|
|
92
|
+
estate_id: estateId,
|
|
93
|
+
channel_account_id: channelAccountId,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
await client.channels.resolveReferences(channelId, reference, undefined);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createClient } from '../';
|
|
2
|
+
import { handlers, rest, server } from '../../mockServer';
|
|
3
|
+
|
|
4
|
+
describe('contacts', () => {
|
|
5
|
+
it('requires authentication', async () => {
|
|
6
|
+
const client = createClient({
|
|
7
|
+
clientId: 'FAKE_ID',
|
|
8
|
+
clientSecret: 'FAKE_SECRET',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
await client.contacts.getOne({
|
|
13
|
+
contactId: 'foo',
|
|
14
|
+
});
|
|
15
|
+
} catch (err: any) {
|
|
16
|
+
expect(err.message).toEqual('client is not authenticated');
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('can fetch a contact', async () => {
|
|
21
|
+
const client = createClient({
|
|
22
|
+
clientId: 'FAKE_ID',
|
|
23
|
+
clientSecret: 'FAKE_SECRET',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
server.use(handlers.authHandler);
|
|
27
|
+
await client.authorize();
|
|
28
|
+
|
|
29
|
+
const contactId = 'FAKE_CONTACT_ID';
|
|
30
|
+
server.use(
|
|
31
|
+
rest.get(
|
|
32
|
+
'https://api.sweepbright.com/services/contacts/:contactId',
|
|
33
|
+
(req, res, ctx) => {
|
|
34
|
+
return res(
|
|
35
|
+
ctx.status(200),
|
|
36
|
+
ctx.json({
|
|
37
|
+
data: {
|
|
38
|
+
id: req.params.contactId,
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const result = await client.contacts.getOne({
|
|
47
|
+
contactId: contactId,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(result).toEqual({ data: { id: contactId } });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('can fetch a contact with negotiators', async () => {
|
|
54
|
+
const client = createClient({
|
|
55
|
+
clientId: 'FAKE_ID',
|
|
56
|
+
clientSecret: 'FAKE_SECRET',
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
server.use(handlers.authHandler);
|
|
60
|
+
await client.authorize();
|
|
61
|
+
|
|
62
|
+
const contactId = 'FAKE_CONTACT_ID';
|
|
63
|
+
server.use(
|
|
64
|
+
rest.get(
|
|
65
|
+
'https://api.sweepbright.com/services/contacts/:contactId?includes=negotiators',
|
|
66
|
+
(req, res, ctx) => {
|
|
67
|
+
return res(
|
|
68
|
+
ctx.status(200),
|
|
69
|
+
ctx.json({
|
|
70
|
+
data: {
|
|
71
|
+
id: req.params.contactId,
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const result = await client.contacts.getOneWithNegotiators({
|
|
80
|
+
contactId: contactId,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(result).toEqual({ data: { id: contactId } });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createClient } from '../';
|
|
2
|
+
import { handlers, rest, server } from '../../mockServer';
|
|
3
|
+
|
|
4
|
+
describe('estates', () => {
|
|
5
|
+
it('requires authentication', async () => {
|
|
6
|
+
const client = createClient({
|
|
7
|
+
clientId: 'FAKE_ID',
|
|
8
|
+
clientSecret: 'FAKE_SECRET',
|
|
9
|
+
});
|
|
10
|
+
try {
|
|
11
|
+
await client.estates.getOne({
|
|
12
|
+
estateId: 'FAKE_ESTATE_ID',
|
|
13
|
+
companyId: 'FAKE_COMPANY_ID',
|
|
14
|
+
});
|
|
15
|
+
} catch (err) {
|
|
16
|
+
await expect((err as any).message).toEqual('client is not authenticated');
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('can fetch a estate', async () => {
|
|
21
|
+
const client = createClient({
|
|
22
|
+
clientId: 'FAKE_ID',
|
|
23
|
+
clientSecret: 'FAKE_SECRET',
|
|
24
|
+
});
|
|
25
|
+
server.use(handlers.authHandler);
|
|
26
|
+
await client.authorize();
|
|
27
|
+
|
|
28
|
+
const estateId = 'FAKE_ESTATE_ID';
|
|
29
|
+
server.use(
|
|
30
|
+
rest.get(
|
|
31
|
+
'https://api.sweepbright.com/services/estates/:estateId',
|
|
32
|
+
(req, res, ctx) => {
|
|
33
|
+
return res(
|
|
34
|
+
ctx.status(200),
|
|
35
|
+
ctx.json({
|
|
36
|
+
data: {
|
|
37
|
+
id: req.params.estateId,
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
const result = await client.estates.getOne({
|
|
45
|
+
estateId: estateId,
|
|
46
|
+
companyId: 'FAKE_COMPANY_ID',
|
|
47
|
+
});
|
|
48
|
+
expect(result).toEqual({ id: estateId });
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createClient } from '../';
|
|
2
|
+
import { handlers, rest, server } from '../../mockServer';
|
|
3
|
+
|
|
4
|
+
describe('leads', () => {
|
|
5
|
+
it('requires authentication', async () => {
|
|
6
|
+
const client = createClient({
|
|
7
|
+
clientId: 'FAKE_ID',
|
|
8
|
+
clientSecret: 'FAKE_SECRET',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
await client.leads.createLead({
|
|
13
|
+
firstName: 'foo',
|
|
14
|
+
lastName: 'bar',
|
|
15
|
+
propertyId: 'baz',
|
|
16
|
+
email: 'john@example.com',
|
|
17
|
+
phone: '999',
|
|
18
|
+
message: "I'm not authenticated",
|
|
19
|
+
portal: 'portal',
|
|
20
|
+
});
|
|
21
|
+
} catch (err: any) {
|
|
22
|
+
expect(err.message).toEqual('client is not authenticated');
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('can put a lead', async () => {
|
|
27
|
+
const client = createClient({
|
|
28
|
+
clientId: 'FAKE_ID',
|
|
29
|
+
clientSecret: 'FAKE_SECRET',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
server.use(handlers.authHandler);
|
|
33
|
+
await client.authorize();
|
|
34
|
+
|
|
35
|
+
const lead = {
|
|
36
|
+
firstName: 'foo',
|
|
37
|
+
lastName: 'bar',
|
|
38
|
+
propertyId: 'PROPERTY_ID',
|
|
39
|
+
email: 'john@example.com',
|
|
40
|
+
phone: '999',
|
|
41
|
+
message: "I'm authenticated",
|
|
42
|
+
portal: 'portal',
|
|
43
|
+
location_preference: {
|
|
44
|
+
country: 'BR',
|
|
45
|
+
postal_codes: ['06010'],
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
server.use(
|
|
50
|
+
rest.put(
|
|
51
|
+
'https://api.sweepbright.com/estates/PROPERTY_ID/leads',
|
|
52
|
+
(_, res, ctx) => {
|
|
53
|
+
return res(
|
|
54
|
+
ctx.status(200),
|
|
55
|
+
ctx.json({
|
|
56
|
+
data: lead,
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const result = await client.leads.createLead(lead);
|
|
64
|
+
|
|
65
|
+
expect(result).toEqual({ data: lead });
|
|
66
|
+
});
|
|
67
|
+
});
|