webflow-api 1.2.2 → 1.3.0

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.
Files changed (61) hide show
  1. package/.eslintrc +31 -0
  2. package/.github/workflows/code-quality.yml +102 -0
  3. package/.github/workflows/npm-publish.yml +21 -0
  4. package/.github/workflows/semgrep.yml +24 -0
  5. package/.prettierignore +5 -0
  6. package/.prettierrc +6 -0
  7. package/README.md +50 -1
  8. package/jest.config.js +17 -0
  9. package/package.json +2 -7
  10. package/src/api/collection.ts +1 -1
  11. package/src/api/item.ts +4 -4
  12. package/src/api/meta.ts +2 -2
  13. package/src/api/oauth.ts +8 -2
  14. package/src/core/error.ts +1 -1
  15. package/src/core/webflow.ts +111 -4
  16. package/tests/api/collection.test.ts +147 -0
  17. package/tests/api/item.test.ts +180 -0
  18. package/tests/api/meta.test.ts +38 -0
  19. package/tests/api/oauth.test.ts +44 -0
  20. package/tests/api/site.test.ts +202 -0
  21. package/tests/api/user.test.ts +139 -0
  22. package/tests/api/webhook.test.ts +82 -0
  23. package/tests/core/error.test.ts +19 -0
  24. package/tests/core/response.test.ts +36 -0
  25. package/tests/core/webflow.test.ts +540 -0
  26. package/tests/fixtures/collection.fixture.ts +374 -0
  27. package/tests/fixtures/index.ts +7 -0
  28. package/tests/fixtures/item.fixture.ts +193 -0
  29. package/tests/fixtures/meta.fixture.ts +34 -0
  30. package/tests/fixtures/oauth.fixture.ts +38 -0
  31. package/tests/fixtures/site.fixture.ts +78 -0
  32. package/tests/fixtures/user.fixture.ts +175 -0
  33. package/tests/fixtures/webhook.fixture.ts +69 -0
  34. package/tsconfig.eslint.json +7 -0
  35. package/tsconfig.json +14 -0
  36. package/dist/api/collection.d.ts +0 -112
  37. package/dist/api/collection.js +0 -94
  38. package/dist/api/index.d.ts +0 -7
  39. package/dist/api/index.js +0 -23
  40. package/dist/api/item.d.ts +0 -177
  41. package/dist/api/item.js +0 -151
  42. package/dist/api/meta.d.ts +0 -53
  43. package/dist/api/meta.js +0 -25
  44. package/dist/api/oauth.d.ts +0 -69
  45. package/dist/api/oauth.js +0 -66
  46. package/dist/api/site.d.ts +0 -140
  47. package/dist/api/site.js +0 -137
  48. package/dist/api/user.d.ts +0 -143
  49. package/dist/api/user.js +0 -119
  50. package/dist/api/webhook.d.ts +0 -102
  51. package/dist/api/webhook.js +0 -80
  52. package/dist/core/error.d.ts +0 -21
  53. package/dist/core/error.js +0 -30
  54. package/dist/core/index.d.ts +0 -3
  55. package/dist/core/index.js +0 -19
  56. package/dist/core/response.d.ts +0 -32
  57. package/dist/core/response.js +0 -26
  58. package/dist/core/webflow.d.ts +0 -386
  59. package/dist/core/webflow.js +0 -445
  60. package/dist/index.d.ts +0 -2
  61. package/yarn.lock +0 -2830
@@ -0,0 +1,147 @@
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
+ });
@@ -0,0 +1,180 @@
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
+ });
@@ -0,0 +1,38 @@
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
+ });
@@ -0,0 +1,44 @@
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
+ });
@@ -0,0 +1,202 @@
1
+ import MockAdapter from "axios-mock-adapter";
2
+ import axios from "axios";
3
+ import { CollectionFixture, SiteFixture, WebhookFixture } from "../fixtures";
4
+ import { Site, Collection, Webhook } from "../../src/api";
5
+
6
+ describe("Sites", () => {
7
+ const mock = new MockAdapter(axios);
8
+ const client = axios.create();
9
+ describe("Static Methods", () => {
10
+ it("should respond with a list of sites", async () => {
11
+ const { response } = SiteFixture.list;
12
+ const path = "/sites";
13
+
14
+ mock.onGet(path).reply(200, response);
15
+ const { data } = await Site.list(client);
16
+
17
+ expect(data).toBeDefined();
18
+ expect(data.length).toBe(response.length);
19
+ expect(data[0]).toMatchObject(response[0]);
20
+ });
21
+
22
+ it("should respond with a single site", async () => {
23
+ const { parameters, response } = SiteFixture.getOne;
24
+ const { siteId } = parameters;
25
+ const path = `/sites/${siteId}`;
26
+
27
+ mock.onGet(path).reply(200, response);
28
+ const { data } = await Site.getOne(parameters, client);
29
+
30
+ expect(data).toBeDefined();
31
+ expect(data._id).toBe(siteId);
32
+ });
33
+
34
+ it("should respond with a list of domains", async () => {
35
+ const { parameters, response } = SiteFixture.domains;
36
+ const { siteId } = parameters;
37
+ const path = `/sites/${siteId}/domains`;
38
+
39
+ mock.onGet(path).reply(200, response);
40
+ const { data } = await Site.domains(parameters, client);
41
+
42
+ expect(data).toBeDefined();
43
+ expect(data.length).toBe(response.length);
44
+ expect(data[0]).toMatchObject(response[0]);
45
+ });
46
+
47
+ it("should publish a site", async () => {
48
+ const { parameters, response } = SiteFixture.publish;
49
+ const { siteId } = parameters;
50
+ const path = `/sites/${siteId}/publish`;
51
+
52
+ mock.onPost(path).reply(200, response);
53
+ const { data } = await Site.publish(parameters, client);
54
+
55
+ expect(data).toBeDefined();
56
+ expect(data.queued).toBe(true);
57
+ });
58
+ });
59
+
60
+ describe("Instance Methods", () => {
61
+ const res = { data: {}, status: 200, statusText: "", headers: {}, config: {} };
62
+ const site = new Site(client, res, SiteFixture.getOne.response);
63
+
64
+ it("should respond with a list of collections", async () => {
65
+ const { parameters, response } = CollectionFixture.list;
66
+ const { siteId } = parameters;
67
+
68
+ const path = `/sites/${siteId}/collections`;
69
+ mock.onGet(path).reply(200, response);
70
+ const spy = jest.spyOn(Collection, "list");
71
+
72
+ const result = await site.collections();
73
+
74
+ expect(spy).toHaveBeenCalledWith({ siteId }, client);
75
+
76
+ expect(result).toBeDefined();
77
+ expect(result.length).toBe(response.length);
78
+
79
+ const [first] = result;
80
+ expect(first._id).toBe(response[0]._id);
81
+
82
+ // collection wrapper functions
83
+ expect(typeof first.item).toBe("function");
84
+ expect(typeof first.items).toBe("function");
85
+ expect(typeof first.removeItem).toBe("function");
86
+ expect(typeof first.createItem).toBe("function");
87
+ expect(typeof first.updateItem).toBe("function");
88
+ });
89
+
90
+ it("should respond with a list of webhooks", async () => {
91
+ const { parameters, response } = WebhookFixture.list;
92
+ const { siteId } = parameters;
93
+
94
+ const path = `/sites/${siteId}/webhooks`;
95
+ mock.onGet(path).reply(200, response);
96
+ const spy = jest.spyOn(Webhook, "list");
97
+
98
+ const result = await site.webhooks();
99
+
100
+ expect(spy).toHaveBeenCalledWith({ siteId }, client);
101
+
102
+ expect(result).toBeDefined();
103
+ expect(result.length).toBe(response.length);
104
+
105
+ const [first] = result;
106
+ expect(first._id).toBe(response[0]._id);
107
+
108
+ // webhook wrapper functions
109
+ expect(typeof first.remove).toBe("function");
110
+ });
111
+
112
+ it("should respond with a single webhook", async () => {
113
+ const { parameters, response } = WebhookFixture.getOne;
114
+ const { siteId, webhookId } = parameters;
115
+
116
+ const path = `/sites/${siteId}/webhooks/${webhookId}`;
117
+ mock.onGet(path).reply(200, response);
118
+ const spy = jest.spyOn(Webhook, "getOne");
119
+
120
+ const result = await site.webhook({ webhookId });
121
+
122
+ expect(spy).toHaveBeenCalledWith({ siteId, webhookId }, client);
123
+
124
+ expect(result).toBeDefined();
125
+ expect(result._id).toBe(response._id);
126
+
127
+ // webhook wrapper functions
128
+ expect(typeof result.remove).toBe("function");
129
+ });
130
+
131
+ it("should create a webhook", async () => {
132
+ const { parameters, response } = WebhookFixture.create;
133
+ const { siteId } = parameters;
134
+
135
+ const path = `/sites/${siteId}/webhooks`;
136
+ const spy = jest.spyOn(Webhook, "create");
137
+ mock.onPost(path).reply(200, response);
138
+
139
+ const result = await site.createWebhook(parameters);
140
+
141
+ expect(spy).toHaveBeenCalledWith(parameters, client);
142
+
143
+ expect(result).toBeDefined();
144
+ expect(result._id).toBe(response._id);
145
+
146
+ // webhook wrapper functions
147
+ expect(typeof result.remove).toBe("function");
148
+ });
149
+
150
+ it("should remove a webhook", async () => {
151
+ const { parameters, response } = WebhookFixture.delete;
152
+ const { siteId, webhookId } = parameters;
153
+
154
+ const path = `/sites/${siteId}/webhooks/${webhookId}`;
155
+ const spy = jest.spyOn(Webhook, "remove");
156
+ mock.onDelete(path).reply(200, response);
157
+
158
+ const result = await site.removeWebhook(parameters);
159
+
160
+ expect(spy).toHaveBeenCalledWith(parameters, client);
161
+
162
+ expect(result).toBeDefined();
163
+ expect(result.deleted).toEqual(response.deleted);
164
+ });
165
+
166
+ it("should respond with a list of domains", async () => {
167
+ const { parameters, response } = SiteFixture.domains;
168
+ const { siteId } = parameters;
169
+
170
+ const path = `/sites/${siteId}/domains`;
171
+ const spy = jest.spyOn(Site, "domains");
172
+ mock.onGet(path).reply(200, response);
173
+
174
+ const result = await site.domains();
175
+
176
+ expect(spy).toHaveBeenCalledWith(parameters, client);
177
+
178
+ expect(result).toBeDefined();
179
+ expect(result.length).toBe(response.length);
180
+
181
+ const [first] = result;
182
+ expect(first._id).toBe(response[0]._id);
183
+ expect(first.name).toBe(response[0].name);
184
+ });
185
+
186
+ it("should publish a site", async () => {
187
+ const { parameters, response } = SiteFixture.publish;
188
+ const { siteId, domains } = parameters;
189
+
190
+ const path = `/sites/${siteId}/publish`;
191
+ const spy = jest.spyOn(Site, "publish");
192
+ mock.onPost(path).reply(200, response);
193
+
194
+ const result = await site.publishSite(domains);
195
+
196
+ expect(spy).toHaveBeenCalledWith(parameters, client);
197
+
198
+ expect(result).toBeDefined();
199
+ expect(result.queued).toBe(true);
200
+ });
201
+ });
202
+ });