webflow-api 1.3.0 → 1.3.1
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/dist/api/collection.d.ts +112 -0
- package/dist/api/collection.js +94 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +23 -0
- package/dist/api/item.d.ts +177 -0
- package/dist/api/item.js +151 -0
- package/dist/api/meta.d.ts +53 -0
- package/dist/api/meta.js +25 -0
- package/dist/api/oauth.d.ts +71 -0
- package/dist/api/oauth.js +71 -0
- package/dist/api/site.d.ts +140 -0
- package/dist/api/site.js +137 -0
- package/dist/api/user.d.ts +143 -0
- package/dist/api/user.js +119 -0
- package/dist/api/webhook.d.ts +102 -0
- package/dist/api/webhook.js +80 -0
- package/dist/core/error.d.ts +21 -0
- package/dist/core/error.js +30 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +19 -0
- package/dist/core/response.d.ts +32 -0
- package/dist/core/response.js +26 -0
- package/dist/core/webflow.d.ts +390 -0
- package/dist/core/webflow.js +518 -0
- package/dist/index.d.ts +2 -0
- package/package.json +7 -1
- package/yarn.lock +2840 -0
- package/.eslintrc +0 -31
- package/.github/workflows/code-quality.yml +0 -102
- package/.github/workflows/npm-publish.yml +0 -21
- package/.github/workflows/semgrep.yml +0 -24
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
- package/jest.config.js +0 -17
- package/tests/api/collection.test.ts +0 -147
- package/tests/api/item.test.ts +0 -180
- package/tests/api/meta.test.ts +0 -38
- package/tests/api/oauth.test.ts +0 -44
- package/tests/api/site.test.ts +0 -202
- package/tests/api/user.test.ts +0 -139
- package/tests/api/webhook.test.ts +0 -82
- package/tests/core/error.test.ts +0 -19
- package/tests/core/response.test.ts +0 -36
- package/tests/core/webflow.test.ts +0 -540
- package/tests/fixtures/collection.fixture.ts +0 -374
- package/tests/fixtures/index.ts +0 -7
- package/tests/fixtures/item.fixture.ts +0 -193
- package/tests/fixtures/meta.fixture.ts +0 -34
- package/tests/fixtures/oauth.fixture.ts +0 -38
- package/tests/fixtures/site.fixture.ts +0 -78
- package/tests/fixtures/user.fixture.ts +0 -175
- package/tests/fixtures/webhook.fixture.ts +0 -69
- package/tsconfig.eslint.json +0 -7
- package/tsconfig.json +0 -14
package/.eslintrc
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"es2021": true,
|
|
4
|
-
"browser": true
|
|
5
|
-
},
|
|
6
|
-
"extends": [
|
|
7
|
-
"eslint:recommended",
|
|
8
|
-
"plugin:@typescript-eslint/recommended",
|
|
9
|
-
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
|
10
|
-
],
|
|
11
|
-
"parser": "@typescript-eslint/parser",
|
|
12
|
-
"parserOptions": {
|
|
13
|
-
"ecmaVersion": 12,
|
|
14
|
-
"project": "tsconfig.eslint.json"
|
|
15
|
-
},
|
|
16
|
-
"plugins": ["@typescript-eslint", "prettier"],
|
|
17
|
-
"rules": {
|
|
18
|
-
"prefer-const": "error",
|
|
19
|
-
"prettier/prettier": "error",
|
|
20
|
-
"@typescript-eslint/no-unused-vars": "off",
|
|
21
|
-
"@typescript-eslint/no-unused-params": "off",
|
|
22
|
-
"@typescript-eslint/no-unsafe-argument": "warn",
|
|
23
|
-
"@typescript-eslint/no-unsafe-assignment": "warn"
|
|
24
|
-
},
|
|
25
|
-
"overrides": [
|
|
26
|
-
{
|
|
27
|
-
"env": { "jest": true, "node": true },
|
|
28
|
-
"files": ["tests/**/*.ts"]
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
name: Code Quality
|
|
2
|
-
|
|
3
|
-
on: push
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
build:
|
|
7
|
-
name: TypeScript Build
|
|
8
|
-
runs-on: ubuntu-latest
|
|
9
|
-
|
|
10
|
-
steps:
|
|
11
|
-
- name: Checkout
|
|
12
|
-
uses: actions/checkout@v2
|
|
13
|
-
|
|
14
|
-
- name: Install Node.js
|
|
15
|
-
uses: actions/setup-node@v1
|
|
16
|
-
with:
|
|
17
|
-
node-version: 14.x
|
|
18
|
-
|
|
19
|
-
- name: yarn install
|
|
20
|
-
run: yarn install
|
|
21
|
-
|
|
22
|
-
- run: yarn build
|
|
23
|
-
name: yarn build
|
|
24
|
-
|
|
25
|
-
typecheck:
|
|
26
|
-
name: TypeScript Typecheck
|
|
27
|
-
runs-on: ubuntu-latest
|
|
28
|
-
|
|
29
|
-
steps:
|
|
30
|
-
- name: Checkout
|
|
31
|
-
uses: actions/checkout@v2
|
|
32
|
-
|
|
33
|
-
- name: Install Node.js
|
|
34
|
-
uses: actions/setup-node@v1
|
|
35
|
-
with:
|
|
36
|
-
node-version: 14.x
|
|
37
|
-
|
|
38
|
-
- name: yarn install
|
|
39
|
-
run: yarn install
|
|
40
|
-
|
|
41
|
-
- run: yarn typecheck
|
|
42
|
-
name: yarn typecheck
|
|
43
|
-
|
|
44
|
-
test:
|
|
45
|
-
name: Jest CI Tests
|
|
46
|
-
runs-on: ubuntu-latest
|
|
47
|
-
|
|
48
|
-
steps:
|
|
49
|
-
- name: Checkout
|
|
50
|
-
uses: actions/checkout@v2
|
|
51
|
-
|
|
52
|
-
- name: Install Node.js
|
|
53
|
-
uses: actions/setup-node@v1
|
|
54
|
-
with:
|
|
55
|
-
node-version: 14.x
|
|
56
|
-
|
|
57
|
-
- name: yarn install
|
|
58
|
-
run: yarn install
|
|
59
|
-
|
|
60
|
-
- name: yarn build
|
|
61
|
-
run: yarn build
|
|
62
|
-
|
|
63
|
-
- run: yarn test:ci
|
|
64
|
-
name: yarn test:ci
|
|
65
|
-
|
|
66
|
-
prettier:
|
|
67
|
-
name: Prettier Formatting
|
|
68
|
-
runs-on: ubuntu-latest
|
|
69
|
-
|
|
70
|
-
steps:
|
|
71
|
-
- name: Checkout
|
|
72
|
-
uses: actions/checkout@v2
|
|
73
|
-
|
|
74
|
-
- name: Install Node.js
|
|
75
|
-
uses: actions/setup-node@v1
|
|
76
|
-
with:
|
|
77
|
-
node-version: 14.x
|
|
78
|
-
|
|
79
|
-
- name: yarn install
|
|
80
|
-
run: yarn install
|
|
81
|
-
|
|
82
|
-
- run: yarn format:check
|
|
83
|
-
name: yarn format:check
|
|
84
|
-
|
|
85
|
-
lint:
|
|
86
|
-
name: ESLint Linting
|
|
87
|
-
runs-on: ubuntu-latest
|
|
88
|
-
|
|
89
|
-
steps:
|
|
90
|
-
- name: Checkout
|
|
91
|
-
uses: actions/checkout@v2
|
|
92
|
-
|
|
93
|
-
- name: Install Node.js
|
|
94
|
-
uses: actions/setup-node@v1
|
|
95
|
-
with:
|
|
96
|
-
node-version: 14.x
|
|
97
|
-
|
|
98
|
-
- name: yarn install
|
|
99
|
-
run: yarn install
|
|
100
|
-
|
|
101
|
-
- run: yarn lint
|
|
102
|
-
name: yarn lint
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
name: Publish to NPM
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
release:
|
|
5
|
-
types: [created]
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
publish-npm:
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
steps:
|
|
11
|
-
- uses: actions/checkout@v3
|
|
12
|
-
- uses: actions/setup-node@v3
|
|
13
|
-
with:
|
|
14
|
-
node-version: 16
|
|
15
|
-
registry-url: https://registry.npmjs.org/
|
|
16
|
-
- run: |
|
|
17
|
-
yarn install
|
|
18
|
-
yarn test
|
|
19
|
-
yarn publish
|
|
20
|
-
env:
|
|
21
|
-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
on:
|
|
2
|
-
workflow_dispatch: {}
|
|
3
|
-
pull_request: {}
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
- master
|
|
8
|
-
paths:
|
|
9
|
-
- .github/workflows/semgrep.yml
|
|
10
|
-
schedule:
|
|
11
|
-
# random HH:MM to avoid a load spike on GitHub Actions at 00:00
|
|
12
|
-
- cron: 34 11 * * *
|
|
13
|
-
name: Semgrep
|
|
14
|
-
jobs:
|
|
15
|
-
semgrep:
|
|
16
|
-
name: semgrep/ci
|
|
17
|
-
runs-on: ubuntu-20.04
|
|
18
|
-
env:
|
|
19
|
-
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
|
|
20
|
-
container:
|
|
21
|
-
image: returntocorp/semgrep
|
|
22
|
-
steps:
|
|
23
|
-
- uses: actions/checkout@v3
|
|
24
|
-
- run: semgrep ci
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/jest.config.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
// A preset that is used as a base for Jest's configuration
|
|
4
|
-
preset: "ts-jest",
|
|
5
|
-
|
|
6
|
-
// The test environment that will be used for testing
|
|
7
|
-
testEnvironment: "node",
|
|
8
|
-
|
|
9
|
-
// A map from regular expressions to paths to transformers
|
|
10
|
-
transform: { "^.+\\.ts?$": "ts-jest" },
|
|
11
|
-
|
|
12
|
-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
13
|
-
transformIgnorePatterns: ["<rootDir>/node_modules/"],
|
|
14
|
-
|
|
15
|
-
// Automatically clear mock calls, instances, contexts and results before every test
|
|
16
|
-
clearMocks: true,
|
|
17
|
-
};
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import MockAdapter from "axios-mock-adapter";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import { ItemFixture, CollectionFixture } from "../fixtures";
|
|
4
|
-
import { Collection, Item } from "../../src/api";
|
|
5
|
-
|
|
6
|
-
describe("Collection", () => {
|
|
7
|
-
const mock = new MockAdapter(axios);
|
|
8
|
-
const client = axios.create();
|
|
9
|
-
|
|
10
|
-
describe("Static Methods", () => {
|
|
11
|
-
it("should respond with a list of site collections", async () => {
|
|
12
|
-
const { parameters, response } = CollectionFixture.list;
|
|
13
|
-
const { siteId } = parameters;
|
|
14
|
-
const path = `/sites/${siteId}/collections`;
|
|
15
|
-
|
|
16
|
-
mock.onGet(path).reply(200, response);
|
|
17
|
-
const { data } = await Collection.list(parameters, client);
|
|
18
|
-
|
|
19
|
-
expect(data).toBeDefined();
|
|
20
|
-
expect(data.length).toBe(response.length);
|
|
21
|
-
expect(data[0]).toMatchObject(response[0]);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("should respond with a single site collection", async () => {
|
|
25
|
-
const { parameters, response } = CollectionFixture.getOne;
|
|
26
|
-
const { collectionId } = parameters;
|
|
27
|
-
const path = `/collections/${collectionId}`;
|
|
28
|
-
|
|
29
|
-
mock.onGet(path).reply(200, response);
|
|
30
|
-
const { data } = await Collection.getOne(parameters, client);
|
|
31
|
-
|
|
32
|
-
expect(data).toBeDefined();
|
|
33
|
-
expect(data._id).toBe(response._id);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe("Instance Methods", () => {
|
|
38
|
-
const res = { data: {}, status: 200, statusText: "", headers: {}, config: {} };
|
|
39
|
-
const collection = new Collection(client, res, CollectionFixture.getOne.response);
|
|
40
|
-
|
|
41
|
-
it("should respond with a list of items", async () => {
|
|
42
|
-
const { parameters, response } = ItemFixture.list;
|
|
43
|
-
const { collectionId } = parameters;
|
|
44
|
-
|
|
45
|
-
const path = `/collections/${collectionId}/items`;
|
|
46
|
-
mock.onGet(path).reply(200, response);
|
|
47
|
-
const spy = jest.spyOn(Item, "list");
|
|
48
|
-
|
|
49
|
-
const result = await collection.items();
|
|
50
|
-
|
|
51
|
-
const _params = { params: undefined, collectionId };
|
|
52
|
-
expect(spy).toBeCalledWith(_params, client);
|
|
53
|
-
|
|
54
|
-
expect(result).toBeDefined();
|
|
55
|
-
expect(result.length).toBe(response.items.length);
|
|
56
|
-
|
|
57
|
-
expect(result[0]._id).toBe(response.items[0]._id);
|
|
58
|
-
|
|
59
|
-
// item wrapper functions
|
|
60
|
-
expect(typeof result[0].update).toBe("function");
|
|
61
|
-
expect(typeof result[0].remove).toBe("function");
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("should respond with a single item", async () => {
|
|
65
|
-
const { parameters, response } = ItemFixture.getOne;
|
|
66
|
-
const { collectionId, itemId } = parameters;
|
|
67
|
-
|
|
68
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
69
|
-
mock.onGet(path).reply(200, response);
|
|
70
|
-
const spy = jest.spyOn(Item, "getOne");
|
|
71
|
-
|
|
72
|
-
const result = await collection.item({ itemId });
|
|
73
|
-
|
|
74
|
-
const _params = { params: undefined, collectionId, itemId };
|
|
75
|
-
expect(spy).toBeCalledWith(_params, client);
|
|
76
|
-
|
|
77
|
-
expect(result).toBeDefined();
|
|
78
|
-
expect(result._id).toBe(response.items[0]._id);
|
|
79
|
-
|
|
80
|
-
// item wrapper functions
|
|
81
|
-
expect(typeof result.update).toBe("function");
|
|
82
|
-
expect(typeof result.remove).toBe("function");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should create an item", async () => {
|
|
86
|
-
const { parameters, response } = ItemFixture.create;
|
|
87
|
-
const { collectionId, fields } = parameters;
|
|
88
|
-
|
|
89
|
-
const path = `/collections/${collectionId}/items`;
|
|
90
|
-
mock.onPost(path).reply(200, response);
|
|
91
|
-
const spy = jest.spyOn(Item, "create");
|
|
92
|
-
|
|
93
|
-
const result = await collection.createItem(fields);
|
|
94
|
-
|
|
95
|
-
const _params = { params: undefined, collectionId, fields };
|
|
96
|
-
expect(spy).toBeCalledWith(_params, client);
|
|
97
|
-
|
|
98
|
-
expect(result).toBeDefined();
|
|
99
|
-
expect(result._id).toBe(response._id);
|
|
100
|
-
|
|
101
|
-
// item wrapper functions
|
|
102
|
-
expect(typeof result.update).toBe("function");
|
|
103
|
-
expect(typeof result.remove).toBe("function");
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("should update an item", async () => {
|
|
107
|
-
const { parameters, response } = ItemFixture.update;
|
|
108
|
-
const { collectionId, itemId, fields } = parameters;
|
|
109
|
-
|
|
110
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
111
|
-
mock.onPut(path).reply(200, response);
|
|
112
|
-
const spy = jest.spyOn(Item, "update");
|
|
113
|
-
|
|
114
|
-
const result = await collection.updateItem({
|
|
115
|
-
itemId,
|
|
116
|
-
fields,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const _params = { params: undefined, collectionId, itemId, fields };
|
|
120
|
-
expect(spy).toBeCalledWith(_params, client);
|
|
121
|
-
|
|
122
|
-
expect(result).toBeDefined();
|
|
123
|
-
expect(result._id).toBe(response._id);
|
|
124
|
-
|
|
125
|
-
// item wrapper functions
|
|
126
|
-
expect(typeof result.update).toBe("function");
|
|
127
|
-
expect(typeof result.remove).toBe("function");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("should remove an item", async () => {
|
|
131
|
-
const { parameters, response } = ItemFixture.remove;
|
|
132
|
-
const { collectionId, itemId } = parameters;
|
|
133
|
-
|
|
134
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
135
|
-
mock.onDelete(path).reply(200, response);
|
|
136
|
-
const spy = jest.spyOn(Item, "remove");
|
|
137
|
-
|
|
138
|
-
const result = await collection.removeItem({ itemId });
|
|
139
|
-
|
|
140
|
-
const _params = { params: undefined, collectionId, itemId };
|
|
141
|
-
expect(spy).toBeCalledWith(_params, client);
|
|
142
|
-
|
|
143
|
-
expect(result).toBeDefined();
|
|
144
|
-
expect(result.deleted).toBe(response.deleted);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
package/tests/api/item.test.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import MockAdapter from "axios-mock-adapter";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import { ItemFixture } from "../fixtures";
|
|
4
|
-
import { Item } from "../../src/api";
|
|
5
|
-
|
|
6
|
-
describe("Items", () => {
|
|
7
|
-
const mock = new MockAdapter(axios);
|
|
8
|
-
const client = axios.create();
|
|
9
|
-
|
|
10
|
-
describe("Static Methods", () => {
|
|
11
|
-
it("should respond with a list of items", async () => {
|
|
12
|
-
const { parameters, response } = ItemFixture.list;
|
|
13
|
-
const { collectionId } = parameters;
|
|
14
|
-
const path = `/collections/${collectionId}/items`;
|
|
15
|
-
|
|
16
|
-
mock.onGet(path).reply(200, response);
|
|
17
|
-
const { data } = await Item.list(parameters, client);
|
|
18
|
-
|
|
19
|
-
expect(data).toBeDefined();
|
|
20
|
-
expect(data.items.length).toBe(response.items.length);
|
|
21
|
-
expect(data.items[0]).toMatchObject(response.items[0]);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("should respond with a single item", async () => {
|
|
25
|
-
const { parameters, response } = ItemFixture.getOne;
|
|
26
|
-
const { collectionId, itemId } = parameters;
|
|
27
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
28
|
-
|
|
29
|
-
mock.onGet(path).reply(200, response);
|
|
30
|
-
const { data } = await Item.getOne(parameters, client);
|
|
31
|
-
|
|
32
|
-
expect(data).toBeDefined();
|
|
33
|
-
expect(data.items[0]._id).toBe(response.items[0]._id);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("should create an item", async () => {
|
|
37
|
-
const { parameters, response } = ItemFixture.create;
|
|
38
|
-
const { collectionId } = parameters;
|
|
39
|
-
|
|
40
|
-
const path = `/collections/${collectionId}/items`;
|
|
41
|
-
|
|
42
|
-
mock.onPost(path).reply(200, response);
|
|
43
|
-
const { data } = await Item.create(parameters, client);
|
|
44
|
-
|
|
45
|
-
expect(data).toBeDefined();
|
|
46
|
-
expect(data._id).toBe(response._id);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("should update an item", async () => {
|
|
50
|
-
const { parameters, response } = ItemFixture.update;
|
|
51
|
-
const { collectionId, itemId } = parameters;
|
|
52
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
53
|
-
|
|
54
|
-
mock.onPut(path).reply(200, response);
|
|
55
|
-
const { data } = await Item.update(parameters, client);
|
|
56
|
-
|
|
57
|
-
expect(data).toBeDefined();
|
|
58
|
-
expect(data._id).toBe(response._id);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("should patch an item", async () => {
|
|
62
|
-
const { parameters, response } = ItemFixture.update;
|
|
63
|
-
const { collectionId, itemId } = parameters;
|
|
64
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
65
|
-
|
|
66
|
-
mock.onPatch(path).reply(200, response);
|
|
67
|
-
const { data } = await Item.patch(parameters, client);
|
|
68
|
-
|
|
69
|
-
expect(data).toBeDefined();
|
|
70
|
-
expect(data._id).toBe(response._id);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should remove an item", async () => {
|
|
74
|
-
const { parameters, response } = ItemFixture.remove;
|
|
75
|
-
const { collectionId, itemId } = parameters;
|
|
76
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
77
|
-
|
|
78
|
-
mock.onDelete(path).reply(200, response);
|
|
79
|
-
const { data } = await Item.remove(parameters, client);
|
|
80
|
-
|
|
81
|
-
expect(data).toBeDefined();
|
|
82
|
-
expect(data.deleted).toBe(response.deleted);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should unpublish multiple items", async () => {
|
|
86
|
-
const { parameters, response } = ItemFixture.unpublish;
|
|
87
|
-
const { collectionId, itemIds } = parameters;
|
|
88
|
-
const path = `/collections/${collectionId}/items`;
|
|
89
|
-
|
|
90
|
-
mock.onDelete(path).reply(200, response);
|
|
91
|
-
const { data } = await Item.unpublish(parameters, client);
|
|
92
|
-
|
|
93
|
-
expect(data).toBeDefined();
|
|
94
|
-
expect(data.deletedItemIds.length).toBe(itemIds.length);
|
|
95
|
-
expect(data.deletedItemIds[0]).toBe(itemIds[0]);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("should live unpublish multiple items", async () => {
|
|
99
|
-
const { parameters, response } = ItemFixture.unpublish;
|
|
100
|
-
const { collectionId, itemIds } = parameters;
|
|
101
|
-
const path = `/collections/${collectionId}/items?live=true`;
|
|
102
|
-
|
|
103
|
-
mock.onDelete(path).reply(200, response);
|
|
104
|
-
const { data } = await Item.unpublish(parameters, client);
|
|
105
|
-
|
|
106
|
-
expect(data).toBeDefined();
|
|
107
|
-
expect(data.deletedItemIds.length).toBe(itemIds.length);
|
|
108
|
-
expect(data.deletedItemIds[0]).toBe(itemIds[0]);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("should publish multiple items", async () => {
|
|
112
|
-
const { parameters, response } = ItemFixture.publish;
|
|
113
|
-
const { collectionId, itemIds } = parameters;
|
|
114
|
-
const path = `/collections/${collectionId}/items/publish`;
|
|
115
|
-
|
|
116
|
-
mock.onPut(path).reply(200, response);
|
|
117
|
-
const { data } = await Item.publish(parameters, client);
|
|
118
|
-
|
|
119
|
-
expect(data).toBeDefined();
|
|
120
|
-
expect(data.publishedItemIds.length).toBe(itemIds.length);
|
|
121
|
-
expect(data.publishedItemIds[0]).toBe(itemIds[0]);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("should live publish multiple items", async () => {
|
|
125
|
-
const { parameters, response } = ItemFixture.publish;
|
|
126
|
-
const { collectionId, itemIds } = parameters;
|
|
127
|
-
const path = `/collections/${collectionId}/items/publish?live=true`;
|
|
128
|
-
|
|
129
|
-
mock.onPut(path).reply(200, response);
|
|
130
|
-
const { data } = await Item.publish(parameters, client);
|
|
131
|
-
|
|
132
|
-
expect(data).toBeDefined();
|
|
133
|
-
expect(data.publishedItemIds.length).toBe(itemIds.length);
|
|
134
|
-
expect(data.publishedItemIds[0]).toBe(itemIds[0]);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe("Instance Methods", () => {
|
|
139
|
-
const res = { data: {}, status: 200, statusText: "", headers: {}, config: {} };
|
|
140
|
-
const item = new Item(client, res, ItemFixture.getOne.response.items[0]);
|
|
141
|
-
|
|
142
|
-
it("should update an item", async () => {
|
|
143
|
-
const { parameters, response } = ItemFixture.update;
|
|
144
|
-
const { collectionId, itemId, fields } = parameters;
|
|
145
|
-
|
|
146
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
147
|
-
mock.onPut(path).reply(200, response);
|
|
148
|
-
const spy = jest.spyOn(Item, "update");
|
|
149
|
-
|
|
150
|
-
const result = await item.update(fields);
|
|
151
|
-
|
|
152
|
-
const _params = { params: undefined, collectionId, itemId, fields };
|
|
153
|
-
expect(spy).toBeCalledWith(_params, client);
|
|
154
|
-
|
|
155
|
-
expect(result).toBeDefined();
|
|
156
|
-
expect(result._id).toBe(response._id);
|
|
157
|
-
|
|
158
|
-
// item wrapper functions
|
|
159
|
-
expect(typeof result.update).toBe("function");
|
|
160
|
-
expect(typeof result.remove).toBe("function");
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("should remove an item", async () => {
|
|
164
|
-
const { parameters, response } = ItemFixture.remove;
|
|
165
|
-
const { collectionId, itemId } = parameters;
|
|
166
|
-
|
|
167
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
168
|
-
mock.onDelete(path).reply(200, response);
|
|
169
|
-
const spy = jest.spyOn(Item, "remove");
|
|
170
|
-
|
|
171
|
-
const result = await item.remove();
|
|
172
|
-
|
|
173
|
-
const _params = { params: undefined, collectionId, itemId };
|
|
174
|
-
expect(spy).toBeCalledWith(_params, client);
|
|
175
|
-
|
|
176
|
-
expect(result).toBeDefined();
|
|
177
|
-
expect(result.deleted).toBe(response.deleted);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|
package/tests/api/meta.test.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import MockAdapter from "axios-mock-adapter";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import { MetaFixture } from "../fixtures";
|
|
4
|
-
import { Meta } from "../../src/api";
|
|
5
|
-
|
|
6
|
-
describe("Meta", () => {
|
|
7
|
-
const mock = new MockAdapter(axios);
|
|
8
|
-
const client = axios.create();
|
|
9
|
-
|
|
10
|
-
it("should get info", async () => {
|
|
11
|
-
const { response } = MetaFixture.info;
|
|
12
|
-
const path = `/info`;
|
|
13
|
-
|
|
14
|
-
mock.onGet(path).reply(200, response);
|
|
15
|
-
const { data } = await Meta.info(client);
|
|
16
|
-
|
|
17
|
-
expect(data).toBeDefined();
|
|
18
|
-
expect(data.users).toEqual(response.users);
|
|
19
|
-
expect(data.sites).toEqual(response.sites);
|
|
20
|
-
expect(data.workspaces).toEqual(response.workspaces);
|
|
21
|
-
expect(data.application).toEqual(response.application);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("should get info about the user", async () => {
|
|
25
|
-
const { response } = MetaFixture.installer;
|
|
26
|
-
|
|
27
|
-
const path = `/user`;
|
|
28
|
-
mock.onGet(path).reply(200, response);
|
|
29
|
-
const { data } = await Meta.user(client);
|
|
30
|
-
|
|
31
|
-
expect(data).toBeDefined();
|
|
32
|
-
expect(data.user).toBeDefined();
|
|
33
|
-
expect(data.user._id).toEqual(response.user._id);
|
|
34
|
-
expect(data.user.email).toEqual(response.user.email);
|
|
35
|
-
expect(data.user.firstName).toEqual(response.user.firstName);
|
|
36
|
-
expect(data.user.lastName).toEqual(response.user.lastName);
|
|
37
|
-
});
|
|
38
|
-
});
|
package/tests/api/oauth.test.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import MockAdapter from "axios-mock-adapter";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import { OAuthFixture } from "../fixtures";
|
|
4
|
-
import { OAuth } from "../../src/api";
|
|
5
|
-
|
|
6
|
-
describe("OAuth", () => {
|
|
7
|
-
const mock = new MockAdapter(axios);
|
|
8
|
-
const client = axios.create();
|
|
9
|
-
|
|
10
|
-
it("should generate an authorization url", () => {
|
|
11
|
-
const { parameters } = OAuthFixture.authorize;
|
|
12
|
-
const { client_id, state, response_type } = parameters;
|
|
13
|
-
|
|
14
|
-
const baseURL = "https://api.test.com";
|
|
15
|
-
const instance = axios.create({ baseURL });
|
|
16
|
-
const url = OAuth.authorizeUrl({ client_id, state }, instance);
|
|
17
|
-
const query = new URLSearchParams({ response_type, client_id, state });
|
|
18
|
-
|
|
19
|
-
expect(url).toBeDefined();
|
|
20
|
-
expect(url).toBe(`${baseURL.replace("api.", "")}/oauth/authorize?${query.toString()}`);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("should generate an access token", async () => {
|
|
24
|
-
const { parameters, response } = OAuthFixture.access_token;
|
|
25
|
-
const path = `/oauth/access_token`;
|
|
26
|
-
|
|
27
|
-
mock.onPost(path).reply(200, response);
|
|
28
|
-
const { data } = await OAuth.accessToken(parameters, client);
|
|
29
|
-
|
|
30
|
-
expect(data).toBeDefined();
|
|
31
|
-
expect(data.access_token).toBe(response.access_token);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should revoke an access token", async () => {
|
|
35
|
-
const { parameters, response } = OAuthFixture.revoke_token;
|
|
36
|
-
const path = `/oauth/revoke_authorization`;
|
|
37
|
-
|
|
38
|
-
mock.onPost(path).reply(200, response);
|
|
39
|
-
const { data } = await OAuth.revokeToken(parameters, client);
|
|
40
|
-
|
|
41
|
-
expect(data).toBeDefined();
|
|
42
|
-
expect(data.didRevoke).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
});
|