@contentstack/datasync-manager 2.0.0 → 2.0.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/LICENSE +1 -1
- package/dist/api.js +4 -2
- package/dist/core/q.js +4 -2
- package/dist/util/index.js +1 -1
- package/dist/util/validations.js +2 -2
- package/package.json +6 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/codeql-analysis.yml +0 -68
- package/.github/workflows/jira.yml +0 -28
- package/.github/workflows/release.yml +0 -53
- package/.github/workflows/sast-scan.yml +0 -11
- package/.github/workflows/sca-scan.yml +0 -15
- package/.github/workflows/secrets-scan.yml +0 -11
- package/.releaserc +0 -9
- package/.talismanrc +0 -4
- package/CODEOWNERS +0 -1
- package/SECURITY.md +0 -27
- package/example/config.js +0 -60
- package/example/index.js +0 -30
- package/test/api.ts +0 -152
- package/test/core/filteredItems.ts +0 -58
- package/test/core/index.ts +0 -18
- package/test/core/inet.ts +0 -23
- package/test/core/q.ts +0 -42
- package/test/core/sync.ts +0 -19
- package/test/core/token-management.ts +0 -40
- package/test/dummy/api-responses/404.ts +0 -3
- package/test/dummy/api-responses/content-type.ts +0 -30
- package/test/dummy/api-responses/delete-asset.ts +0 -9
- package/test/dummy/api-responses/delete-content-type.ts +0 -6
- package/test/dummy/api-responses/delete-entry.ts +0 -9
- package/test/dummy/api-responses/delete.ts +0 -32
- package/test/dummy/api-responses/empty.ts +0 -7
- package/test/dummy/api-responses/entries.ts +0 -31
- package/test/dummy/api-responses/filter-items.ts +0 -32
- package/test/dummy/api-responses/global-field.ts +0 -175
- package/test/dummy/api-responses/markdown-content-type.ts +0 -202
- package/test/dummy/api-responses/markdown-entries.ts +0 -56
- package/test/dummy/api-responses/mixed.ts +0 -77
- package/test/dummy/api-responses/publish-asset.ts +0 -14
- package/test/dummy/api-responses/publish-entry.ts +0 -14
- package/test/dummy/api-responses/publish.ts +0 -35
- package/test/dummy/api-responses/references-content-type-2.ts +0 -240
- package/test/dummy/api-responses/references-content-type.ts +0 -272
- package/test/dummy/api-responses/references-entries.ts +0 -156
- package/test/dummy/api-responses/unpublish-asset.ts +0 -9
- package/test/dummy/api-responses/unpublish-entry.ts +0 -9
- package/test/dummy/api-responses/unpublish.ts +0 -26
- package/test/dummy/config.ts +0 -34
- package/test/dummy/connector-listener-instances.ts +0 -69
- package/test/dummy/filter-items.ts +0 -32
- package/test/dummy/plugins/myplugin1/index.js +0 -20
- package/test/dummy/plugins/myplugin2/index.js +0 -20
- package/test/dummy/references-content-type.ts +0 -340
- package/test/dummy/references-entry-expected.ts +0 -161
- package/test/dummy/references-entry.ts +0 -95
- package/test/index.ts +0 -330
- package/test/util/fs.ts +0 -92
- package/test/util/index.ts +0 -157
- package/test/util/log-save-filtered-items.ts +0 -42
- package/test/util/validations.ts +0 -158
- package/tslint.json +0 -53
package/test/index.ts
DELETED
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs'
|
|
2
|
-
import { cloneDeep, merge } from 'lodash'
|
|
3
|
-
import nock from 'nock'
|
|
4
|
-
import { join } from 'path'
|
|
5
|
-
import { get } from '../src/api'
|
|
6
|
-
import { setAssetStore, setConfig, setContentStore, setListener, start } from '../src'
|
|
7
|
-
import { config as internalConfig } from '../src/config'
|
|
8
|
-
import { setLogger } from '../src/util/logger'
|
|
9
|
-
import { contentType as contentTypeSchema } from './dummy/api-responses/content-type'
|
|
10
|
-
import { response as deleteResponse } from './dummy/api-responses/delete'
|
|
11
|
-
import { response as emptyResponse } from './dummy/api-responses/empty'
|
|
12
|
-
import { response as mixedUnpublishResponse } from './dummy/api-responses/entries'
|
|
13
|
-
import { contentType as rteSchema } from './dummy/api-responses/markdown-content-type'
|
|
14
|
-
import { response as rteEntries } from './dummy/api-responses/markdown-entries'
|
|
15
|
-
import { response as publishResponse } from './dummy/api-responses/publish'
|
|
16
|
-
import { contentType as referenceSchema } from './dummy/api-responses/references-content-type'
|
|
17
|
-
import { contentType as reference2Schema } from './dummy/api-responses/references-content-type-2'
|
|
18
|
-
import { response as referencesEntries } from './dummy/api-responses/references-entries'
|
|
19
|
-
import { config as testConfig } from './dummy/config'
|
|
20
|
-
import { assetConnector, contentConnector, listener } from './dummy/connector-listener-instances'
|
|
21
|
-
import { response as contentTypeWithGlobalFieldResponse } from './dummy/api-responses/global-field'
|
|
22
|
-
|
|
23
|
-
const packageInfo: any = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'))
|
|
24
|
-
|
|
25
|
-
describe('core', () => {
|
|
26
|
-
beforeAll(() => {
|
|
27
|
-
setLogger()
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
nock('https://api.localhost.io', { reqheaders: {
|
|
32
|
-
'access_token': 'dummyDeliveryToken',
|
|
33
|
-
'api_key': 'dummyApiKey',
|
|
34
|
-
'x-user-agent': `datasync-manager/v${packageInfo.version}`,
|
|
35
|
-
}})
|
|
36
|
-
.get('/v3/stacks/sync/publish-success')
|
|
37
|
-
.query({sync_token: 'dummySyncToken', environment: 'test', limit: 100})
|
|
38
|
-
.reply(200, publishResponse)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
beforeEach(() => {
|
|
42
|
-
nock('https://api.localhost.io', { reqheaders: {
|
|
43
|
-
'access_token': 'dummyDeliveryToken',
|
|
44
|
-
'api_key': 'dummyApiKey',
|
|
45
|
-
'x-user-agent': `datasync-manager/v${packageInfo.version}`,
|
|
46
|
-
}})
|
|
47
|
-
.get('/v3/stacks/sync')
|
|
48
|
-
.query({pagination_token: 'publish-token', environment: 'test', limit: 100})
|
|
49
|
-
.reply(200, emptyResponse)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
nock('https://api.localhost.io', { reqheaders: {
|
|
54
|
-
'access_token': 'dummyDeliveryToken',
|
|
55
|
-
'api_key': 'dummyApiKey',
|
|
56
|
-
'x-user-agent': `datasync-manager/v${packageInfo.version}`,
|
|
57
|
-
}})
|
|
58
|
-
.get('/v3/stacks/sync/publish-success')
|
|
59
|
-
.query({pagination_token: 'publish-token', environment: 'test', limit: 100})
|
|
60
|
-
.reply(200, emptyResponse)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
nock('https://api.localhost.io', { reqheaders: {
|
|
65
|
-
'access_token': 'dummyDeliveryToken',
|
|
66
|
-
'api_key': 'dummyApiKey',
|
|
67
|
-
'x-user-agent': `datasync-manager/v${packageInfo.version}`,
|
|
68
|
-
}})
|
|
69
|
-
// tslint:disable-next-line: max-line-length
|
|
70
|
-
// "url": "https://api.localhost.io/v3/stacks/sync/publish-success?environment=test&limit=100&sync_token=dummySyncToken",
|
|
71
|
-
|
|
72
|
-
.get('/v3/stacks/sync')
|
|
73
|
-
.query({sync_token: 'dummySyncToken', environment: 'test', limit: 100})
|
|
74
|
-
.reply(200, publishResponse)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
nock('https://api.localhost.io', { reqheaders: {
|
|
79
|
-
'access_token': 'dummyDeliveryToken',
|
|
80
|
-
'api_key': 'dummyApiKey',
|
|
81
|
-
'x-user-agent': `datasync-manager/v${packageInfo.version}`,
|
|
82
|
-
}})
|
|
83
|
-
.get('/v3/stacks/sync/unpublish-success')
|
|
84
|
-
.query({sync_token: 'dummySyncToken', environment: 'test', limit: 100})
|
|
85
|
-
.reply(200, mixedUnpublishResponse)
|
|
86
|
-
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
beforeEach(() => {
|
|
90
|
-
nock('https://api.localhost.io', { reqheaders: {
|
|
91
|
-
'access_token': 'dummyDeliveryToken',
|
|
92
|
-
'api_key': 'dummyApiKey',
|
|
93
|
-
'x-user-agent': `datasync-manager/v${packageInfo.version}`,
|
|
94
|
-
}})
|
|
95
|
-
.get('/v3/stacks/sync/delete-success')
|
|
96
|
-
.query({pagination_token: 'dummyPaginationToken', environment: 'test', limit: 100})
|
|
97
|
-
.reply(200, deleteResponse)
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
beforeEach(() => {
|
|
101
|
-
nock('https://api.localhost.io', { reqheaders: {
|
|
102
|
-
'access_token': 'dummyDeliveryToken',
|
|
103
|
-
'api_key': 'dummyApiKey',
|
|
104
|
-
'x-user-agent': `datasync-manager/v${packageInfo.version}`,
|
|
105
|
-
}})
|
|
106
|
-
.get('/v3/stacks/sync/rte-success')
|
|
107
|
-
.query({sync_token: 'dummyRTEToken', environment: 'test', limit: 100})
|
|
108
|
-
.reply(200, rteEntries)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
beforeEach(() => {
|
|
112
|
-
nock('https://api.localhost.io', { reqheaders: {
|
|
113
|
-
'access_token': 'dummyDeliveryToken',
|
|
114
|
-
'api_key': 'dummyApiKey',
|
|
115
|
-
'x-user-agent': `datasync-manager/v${packageInfo.version}`,
|
|
116
|
-
}})
|
|
117
|
-
.get('/v3/stacks/sync/references-success')
|
|
118
|
-
.query({sync_token: 'dummyReferencesToken', environment: 'test', limit: 100})
|
|
119
|
-
.reply(200, referencesEntries)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
beforeEach(() => {
|
|
123
|
-
nock('https://api.localhost.io', { reqheaders: {
|
|
124
|
-
'access_token': 'dummyDeliveryToken',
|
|
125
|
-
'api_key': 'dummyApiKey',
|
|
126
|
-
'x-user-agent': `datasync-manager/v${packageInfo.version}`,
|
|
127
|
-
}})
|
|
128
|
-
.get('/v3/stacks/sync')
|
|
129
|
-
.query({sync_token: 'dummySyncToken', environment: 'test', limit: 100})
|
|
130
|
-
.reply(200, deleteResponse)
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
beforeEach(() => {
|
|
134
|
-
nock('https://api.localhost.io')
|
|
135
|
-
.get('/v3/content_types/authors')
|
|
136
|
-
.query(true)
|
|
137
|
-
.reply(200, contentTypeSchema)
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
beforeEach(() => {
|
|
141
|
-
nock('https://api.localhost.io')
|
|
142
|
-
.get('/v3/content_types/sample_three')
|
|
143
|
-
.query(true)
|
|
144
|
-
.reply(200, rteSchema)
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
beforeEach(() => {
|
|
148
|
-
nock('https://api.localhost.io')
|
|
149
|
-
.get('/v3/content_types/sample_fourt')
|
|
150
|
-
.query(true)
|
|
151
|
-
.reply(200, referenceSchema)
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
beforeEach(() => {
|
|
155
|
-
nock('https://api.localhost.io')
|
|
156
|
-
.get('/v3/content_types/references')
|
|
157
|
-
.query(true)
|
|
158
|
-
.reply(200, reference2Schema)
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
beforeEach(() => {
|
|
162
|
-
nock('https://api.localhost.io')
|
|
163
|
-
.get('/v3/stacks/sync/unpublish-success')
|
|
164
|
-
.reply(200, publishResponse)
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
beforeEach(() => {
|
|
168
|
-
nock('https://api.localhost.io',{
|
|
169
|
-
reqheaders:{
|
|
170
|
-
'access_token':'dummyDeliveryToken',
|
|
171
|
-
'api_key':'dummyApiKey',
|
|
172
|
-
'x-user-agent':`datasync-manager/v${packageInfo.version}`
|
|
173
|
-
},
|
|
174
|
-
})
|
|
175
|
-
.get('/v3/content_types/test?include_global_field_schema=true')
|
|
176
|
-
.reply(200,contentTypeWithGlobalFieldResponse)
|
|
177
|
-
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
// afterEach((done) => {
|
|
181
|
-
// // wait 5 sec before continuing
|
|
182
|
-
// setTimeout(done, 5000)
|
|
183
|
-
// })
|
|
184
|
-
|
|
185
|
-
test('set content connector without errors', () => {
|
|
186
|
-
expect(setContentStore((contentConnector as any))).toBeUndefined()
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
test('set asset connector without errors', () => {
|
|
190
|
-
expect(setAssetStore((assetConnector as any))).toBeUndefined()
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
test('set listener without errors', () => {
|
|
194
|
-
expect(setListener((listener as any))).toBeUndefined()
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
test('set config without errors', () => {
|
|
198
|
-
expect(setConfig(testConfig)).toBeUndefined()
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
test('process mixed data without errors', async () => {
|
|
202
|
-
const configs = cloneDeep(merge({}, internalConfig, testConfig))
|
|
203
|
-
const contentstack = configs.contentstack
|
|
204
|
-
contentstack.sync_token = 'dummySyncToken'
|
|
205
|
-
contentstack.host = 'api.localhost.io'
|
|
206
|
-
setContentStore((contentConnector as any))
|
|
207
|
-
setAssetStore((assetConnector as any))
|
|
208
|
-
setListener((listener as any))
|
|
209
|
-
const status = (await start(configs))
|
|
210
|
-
expect(status).toBeUndefined()
|
|
211
|
-
// return start(configs).then((status) => {
|
|
212
|
-
// expect(status).toBeUndefined()
|
|
213
|
-
// }).catch((error) => {
|
|
214
|
-
// expect(error).toBeNull()
|
|
215
|
-
// })
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
test('process publish data without errors', async () => {
|
|
219
|
-
const configs = cloneDeep(merge({}, internalConfig, testConfig))
|
|
220
|
-
const contentstack = configs.contentstack
|
|
221
|
-
contentstack.sync_token = 'dummySyncToken'
|
|
222
|
-
contentstack.host = 'api.localhost.io'
|
|
223
|
-
contentstack.apis.sync += '/publish-success'
|
|
224
|
-
setContentStore((contentConnector as any))
|
|
225
|
-
setAssetStore((assetConnector as any))
|
|
226
|
-
setListener((listener as any))
|
|
227
|
-
|
|
228
|
-
const status = (await start(configs))
|
|
229
|
-
expect(status).toBeUndefined()
|
|
230
|
-
// return start(configs).then((status) => {
|
|
231
|
-
// expect(status).toBeUndefined()
|
|
232
|
-
// }).catch((error) => {
|
|
233
|
-
// expect(error).toBeNull()
|
|
234
|
-
// })
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
test('process published RTE data without errors', async () => {
|
|
238
|
-
const configs = cloneDeep(merge({}, internalConfig, testConfig))
|
|
239
|
-
const contentstack = configs.contentstack
|
|
240
|
-
contentstack.sync_token = 'dummyRTEToken'
|
|
241
|
-
contentstack.host = 'api.localhost.io'
|
|
242
|
-
contentstack.apis.sync += '/rte-success'
|
|
243
|
-
setContentStore((contentConnector as any))
|
|
244
|
-
setAssetStore((assetConnector as any))
|
|
245
|
-
setListener((listener as any))
|
|
246
|
-
|
|
247
|
-
const status = (await start(configs))
|
|
248
|
-
expect(status).toBeUndefined()
|
|
249
|
-
// return start(configs).then((status) => {
|
|
250
|
-
// expect(status).toBeUndefined()
|
|
251
|
-
// }).catch((error) => {
|
|
252
|
-
// expect(error).toBeNull()
|
|
253
|
-
// })
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
test('process published references data without errors', async () => {
|
|
257
|
-
const configs = cloneDeep(merge({}, internalConfig, testConfig))
|
|
258
|
-
const contentstack = configs.contentstack
|
|
259
|
-
contentstack.sync_token = 'dummyReferencesToken'
|
|
260
|
-
contentstack.host = 'api.localhost.io'
|
|
261
|
-
contentstack.apis.sync += '/references-success'
|
|
262
|
-
setContentStore((contentConnector as any))
|
|
263
|
-
setAssetStore((assetConnector as any))
|
|
264
|
-
setListener((listener as any))
|
|
265
|
-
|
|
266
|
-
const status = (await start(configs))
|
|
267
|
-
expect(status).toBeUndefined()
|
|
268
|
-
// return start(configs).then((status) => {
|
|
269
|
-
// expect(status).toBeUndefined()
|
|
270
|
-
// }).catch((error) => {
|
|
271
|
-
// expect(error).toBeNull()
|
|
272
|
-
// })
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
test('process unpublish data without errors', async () => {
|
|
276
|
-
const configs = cloneDeep(merge({}, internalConfig, testConfig))
|
|
277
|
-
const contentstack = configs.contentstack
|
|
278
|
-
contentstack.sync_token = 'dummySyncToken'
|
|
279
|
-
contentstack.host = 'api.localhost.io'
|
|
280
|
-
contentstack.apis.sync += '/unpublish-success'
|
|
281
|
-
setContentStore((contentConnector as any))
|
|
282
|
-
setAssetStore((assetConnector as any))
|
|
283
|
-
setListener((listener as any))
|
|
284
|
-
const status = (await start(configs))
|
|
285
|
-
expect(status).toBeUndefined()
|
|
286
|
-
// return start(configs).then((status) => {
|
|
287
|
-
// expect(status).toBeUndefined()
|
|
288
|
-
// }).catch((error) => {
|
|
289
|
-
// expect(error).toBeNull()
|
|
290
|
-
// })
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
test('process deleted data without errors', async () => {
|
|
294
|
-
const configs = cloneDeep(merge({}, internalConfig, testConfig))
|
|
295
|
-
delete configs.plugins
|
|
296
|
-
const contentstack: any = configs.contentstack
|
|
297
|
-
contentstack.pagination_token = 'dummyPaginationToken'
|
|
298
|
-
contentstack.host = 'api.localhost.io'
|
|
299
|
-
contentstack.apis.sync += '/delete-success'
|
|
300
|
-
setContentStore((contentConnector as any))
|
|
301
|
-
setAssetStore((assetConnector as any))
|
|
302
|
-
setListener((listener as any))
|
|
303
|
-
delete contentstack.sync_token
|
|
304
|
-
setConfig(configs)
|
|
305
|
-
|
|
306
|
-
const status = (await start(configs))
|
|
307
|
-
expect(status).toBeUndefined()
|
|
308
|
-
// return start(configs).then((status) => {
|
|
309
|
-
// expect(status).toBeUndefined()
|
|
310
|
-
// }).catch((error) => {
|
|
311
|
-
// expect(error).toBeNull()
|
|
312
|
-
// })
|
|
313
|
-
})
|
|
314
|
-
|
|
315
|
-
test('content-type-schema-with-global-field',()=>{
|
|
316
|
-
const request={
|
|
317
|
-
path:'/v3/content_types/test?include_global_field_schema=true'
|
|
318
|
-
}
|
|
319
|
-
let expectedGlobalFieldSchema={
|
|
320
|
-
"data_type":"global_field",
|
|
321
|
-
"uid":"global_field",
|
|
322
|
-
"schema":expect.anything()
|
|
323
|
-
}
|
|
324
|
-
return get(request).then((response)=>{
|
|
325
|
-
expect(response['content_type'].schema).toEqual(expect.arrayContaining([
|
|
326
|
-
expect.objectContaining(expectedGlobalFieldSchema)
|
|
327
|
-
]))
|
|
328
|
-
})
|
|
329
|
-
})
|
|
330
|
-
})
|
package/test/util/fs.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { cloneDeep, merge } from 'lodash'
|
|
2
|
-
import { join, resolve } from 'path'
|
|
3
|
-
import rimraf from 'rimraf'
|
|
4
|
-
import { config as internalConfig } from '../../src/config'
|
|
5
|
-
import { buildConfigPaths } from '../../src/util/build-paths'
|
|
6
|
-
import { mkdir, readFile, readFileSync, writeFile } from '../../src/util/fs'
|
|
7
|
-
import { setLogger } from '../../src/util/logger'
|
|
8
|
-
import { config } from '../dummy/config'
|
|
9
|
-
|
|
10
|
-
const configs: any = cloneDeep(merge({}, internalConfig, config))
|
|
11
|
-
|
|
12
|
-
describe('fs utility', () => {
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
setLogger()
|
|
15
|
-
configs.paths = buildConfigPaths()
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
afterAll(() => {
|
|
19
|
-
const fPath = resolve(join(__dirname, '..', '..', 'file.json'))
|
|
20
|
-
rimraf.sync(fPath)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('write file should execute without errors', () => {
|
|
24
|
-
const filePath = resolve(join(__dirname, '..', '..', 'file.json'))
|
|
25
|
-
const data = {
|
|
26
|
-
sample: 'data',
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return writeFile(filePath, data).then((result) => {
|
|
30
|
-
expect(result).toBeUndefined()
|
|
31
|
-
}).catch((error) => {
|
|
32
|
-
expect(error).toBeUndefined()
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test('read file should execute without errors', () => {
|
|
37
|
-
const filePath = resolve(join(__dirname, '..', '..', 'file.json'))
|
|
38
|
-
const data = {
|
|
39
|
-
sample: 'data',
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return readFile(filePath).then((result) => {
|
|
43
|
-
const res = JSON.parse((result as any))
|
|
44
|
-
expect(res).toHaveProperty('sample')
|
|
45
|
-
expect(res).toMatchObject(data)
|
|
46
|
-
}).catch((error) => {
|
|
47
|
-
expect(error).toBeUndefined()
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('read non existent file and throw error', () => {
|
|
52
|
-
const filePath = resolve(join(__dirname, '..', '..', 'file-not-exists.json'))
|
|
53
|
-
const err = `ENOENT: no such file or directory, stat '${filePath}'`
|
|
54
|
-
|
|
55
|
-
return readFile(filePath).then((result) => {
|
|
56
|
-
expect(result).toBeUndefined()
|
|
57
|
-
}).catch((error) => {
|
|
58
|
-
expect(error.message).toEqual(err)
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('read file sync without errors', () => {
|
|
63
|
-
const filePath = resolve(join(__dirname, '..', '..', 'file.json'))
|
|
64
|
-
const data = {
|
|
65
|
-
sample: 'data',
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const obj: any = JSON.parse(readFileSync(filePath).toString())
|
|
69
|
-
|
|
70
|
-
expect(obj).toEqual(data)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
test('read non existent file sync with errors', () => {
|
|
74
|
-
const filePath = resolve(join(__dirname, '..', '..', 'file-not-exists.json'))
|
|
75
|
-
const str = `Invalid 'read' operation on file. Expected ${filePath} to be of type 'file'!`
|
|
76
|
-
const err: any = new Error(str)
|
|
77
|
-
err.code = 'IOORFS'
|
|
78
|
-
// expect(readFileSync(filePath)).toThrowError(err)
|
|
79
|
-
expect(() => {
|
|
80
|
-
readFileSync(filePath)
|
|
81
|
-
}).toThrow(/^Invalid 'read' operation on file. Expected (.*) to be of type 'file'!/)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
test('make directory without errors', () => {
|
|
85
|
-
const dirPath = resolve(join(__dirname, '..', '..', '..', 'test-mkdir'))
|
|
86
|
-
// expect(mkdir(dirPath)).resolves.toBeUndefined()
|
|
87
|
-
|
|
88
|
-
return mkdir(dirPath).then((result) => {
|
|
89
|
-
expect(result).toBeUndefined()
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
})
|
package/test/util/index.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { cloneDeep, merge } from 'lodash'
|
|
2
|
-
import { setConfig } from '../../src'
|
|
3
|
-
import { config as internalConfig } from '../../src/config'
|
|
4
|
-
import { filterItems, formatItems } from '../../src/util'
|
|
5
|
-
import { buildConfigPaths } from '../../src/util/build-paths'
|
|
6
|
-
import { setLogger } from '../../src/util/logger'
|
|
7
|
-
import { config } from '../dummy/config'
|
|
8
|
-
import { response } from '../dummy/filter-items'
|
|
9
|
-
|
|
10
|
-
const conf: any = cloneDeep(merge({}, internalConfig, config))
|
|
11
|
-
|
|
12
|
-
describe('core-utilities', () => {
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
setLogger()
|
|
15
|
-
conf.paths = buildConfigPaths()
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
describe('# Format items', () => {
|
|
19
|
-
test('format items: asset publish', () => {
|
|
20
|
-
const items = [
|
|
21
|
-
{
|
|
22
|
-
action: 'publish',
|
|
23
|
-
content_type_uid: 'sys_assets',
|
|
24
|
-
data: {
|
|
25
|
-
publish_details: {
|
|
26
|
-
locale: 'en-us',
|
|
27
|
-
},
|
|
28
|
-
uid: 'a1',
|
|
29
|
-
},
|
|
30
|
-
type: 'asset_published',
|
|
31
|
-
},
|
|
32
|
-
]
|
|
33
|
-
const configs = cloneDeep(merge({}, internalConfig, config))
|
|
34
|
-
|
|
35
|
-
const formattedItem = formatItems(items, configs)[0]
|
|
36
|
-
expect(formattedItem).toHaveProperty('_content_type_uid')
|
|
37
|
-
// expect(formattedItem).not.toHaveProperty('content_type_uid')
|
|
38
|
-
expect(formattedItem).toHaveProperty('_synced_at')
|
|
39
|
-
expect(formattedItem).toHaveProperty('action')
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
test('asset unpublish should work without errors', () => {
|
|
43
|
-
const items = [
|
|
44
|
-
{
|
|
45
|
-
action: 'unpublish',
|
|
46
|
-
content_type_uid: 'sys_assets',
|
|
47
|
-
data: {
|
|
48
|
-
locale: 'en-us',
|
|
49
|
-
uid: 'a1',
|
|
50
|
-
},
|
|
51
|
-
type: 'asset_unpublished',
|
|
52
|
-
},
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
const configs = cloneDeep(merge({}, internalConfig, config))
|
|
56
|
-
const formattedItem = formatItems(items, configs)[0]
|
|
57
|
-
expect(formattedItem).toHaveProperty('_content_type_uid')
|
|
58
|
-
// expect(formattedItem).not.toHaveProperty('content_type_uid')
|
|
59
|
-
expect(formattedItem).toHaveProperty('action')
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('asset delete should work without errors', () => {
|
|
63
|
-
const items = [
|
|
64
|
-
{
|
|
65
|
-
action: 'delete',
|
|
66
|
-
content_type_uid: 'sys_assets',
|
|
67
|
-
data: {
|
|
68
|
-
locale: 'en-us',
|
|
69
|
-
uid: 'a1',
|
|
70
|
-
},
|
|
71
|
-
type: 'asset_deleted',
|
|
72
|
-
},
|
|
73
|
-
]
|
|
74
|
-
|
|
75
|
-
const configs = cloneDeep(merge({}, internalConfig, config))
|
|
76
|
-
const formattedItem = formatItems(items, configs)[0]
|
|
77
|
-
expect(formattedItem).toHaveProperty('_content_type_uid')
|
|
78
|
-
// expect(formattedItem).not.toHaveProperty('content_type_uid')
|
|
79
|
-
expect(formattedItem).toHaveProperty('action')
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test('entry publish should work without errors', () => {
|
|
83
|
-
const items = [
|
|
84
|
-
{
|
|
85
|
-
content_type_uid: 'ct1',
|
|
86
|
-
data: {
|
|
87
|
-
publish_details: {
|
|
88
|
-
locale: 'en-us',
|
|
89
|
-
},
|
|
90
|
-
uid: 'e1',
|
|
91
|
-
},
|
|
92
|
-
// tslint:disable-next-line: object-literal-sort-keys
|
|
93
|
-
action: 'publish',
|
|
94
|
-
type: 'entry_published',
|
|
95
|
-
},
|
|
96
|
-
]
|
|
97
|
-
const configs = cloneDeep(merge({}, internalConfig, config))
|
|
98
|
-
const formattedItem = formatItems(items, configs)[0]
|
|
99
|
-
expect(formattedItem).toHaveProperty('_content_type_uid')
|
|
100
|
-
// expect(formattedItem).not.toHaveProperty('content_type_uid')
|
|
101
|
-
expect(formattedItem).toHaveProperty('_synced_at')
|
|
102
|
-
expect(formattedItem).toHaveProperty('action')
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
test('entry unpublish should work without errors', () => {
|
|
106
|
-
const items = [
|
|
107
|
-
{
|
|
108
|
-
content_type_uid: 'ct1',
|
|
109
|
-
data: {
|
|
110
|
-
locale: 'en-us',
|
|
111
|
-
uid: 'e1',
|
|
112
|
-
},
|
|
113
|
-
type: 'entry_unpublished',
|
|
114
|
-
},
|
|
115
|
-
]
|
|
116
|
-
const configs = cloneDeep(merge({}, internalConfig, config))
|
|
117
|
-
const formattedItem = formatItems(items, configs)[0]
|
|
118
|
-
expect(formattedItem).toHaveProperty('_content_type_uid')
|
|
119
|
-
// expect(formattedItem).not.toHaveProperty('content_type_uid')
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
test('entry delete should work without errors', () => {
|
|
123
|
-
const items = [
|
|
124
|
-
{
|
|
125
|
-
action: 'delete',
|
|
126
|
-
content_type_uid: 'ct1',
|
|
127
|
-
data: {
|
|
128
|
-
locale: 'en-us',
|
|
129
|
-
uid: 'e1',
|
|
130
|
-
},
|
|
131
|
-
type: 'entry_deleted',
|
|
132
|
-
},
|
|
133
|
-
]
|
|
134
|
-
const configs = cloneDeep(merge({}, internalConfig, config))
|
|
135
|
-
const formattedItem = formatItems(items, configs)[0]
|
|
136
|
-
expect(formattedItem).toHaveProperty('_content_type_uid')
|
|
137
|
-
// expect(formattedItem).not.toHaveProperty('content_type_uid')
|
|
138
|
-
expect(formattedItem).toHaveProperty('action')
|
|
139
|
-
})
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
describe('filter items', () => {
|
|
143
|
-
test('process filtered items (pagination_token)', () => {
|
|
144
|
-
const resp: any = cloneDeep(response)
|
|
145
|
-
// add an item locale that does not exist
|
|
146
|
-
const item = cloneDeep(resp.items[0])
|
|
147
|
-
item.data.publish_details.locale = 'abcd'
|
|
148
|
-
resp.items.push(item)
|
|
149
|
-
setConfig(conf)
|
|
150
|
-
return filterItems(resp, conf).then((output) => {
|
|
151
|
-
expect(output).toBeUndefined()
|
|
152
|
-
}).catch((error) => {
|
|
153
|
-
expect(error).toBeNull()
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
})
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { writeFileSync } from 'fs'
|
|
2
|
-
import { cloneDeep, merge } from 'lodash'
|
|
3
|
-
import { sync as mkdirpSync } from 'mkdirp'
|
|
4
|
-
import { join, resolve } from 'path'
|
|
5
|
-
import { sync as rimrafSync } from 'rimraf'
|
|
6
|
-
|
|
7
|
-
import { setConfig } from '../../src'
|
|
8
|
-
import { config as internalConfig } from '../../src/config'
|
|
9
|
-
import { buildConfigPaths } from '../../src/util/build-paths'
|
|
10
|
-
import { setLogger } from '../../src/util/logger'
|
|
11
|
-
import { saveFilteredItems } from '../../src/util/unprocessible'
|
|
12
|
-
import { config } from '../dummy/config'
|
|
13
|
-
|
|
14
|
-
const configs: any = cloneDeep(merge({}, internalConfig, config))
|
|
15
|
-
setLogger()
|
|
16
|
-
configs.paths = buildConfigPaths()
|
|
17
|
-
|
|
18
|
-
describe('save filtered items', () => {
|
|
19
|
-
afterAll(() => {
|
|
20
|
-
const filterItemDir = resolve(join(__dirname, '..', '..', 'test-filteritems'))
|
|
21
|
-
rimrafSync(filterItemDir)
|
|
22
|
-
})
|
|
23
|
-
test('invoke save filter, when filter items file exists', () => {
|
|
24
|
-
const filterItemDir = resolve(join(__dirname, '..', '..', 'test-filteritems'))
|
|
25
|
-
const filterItemPath = join(filterItemDir, 'filtered-items.json')
|
|
26
|
-
const filteredData = [
|
|
27
|
-
{
|
|
28
|
-
key: 'random data',
|
|
29
|
-
},
|
|
30
|
-
]
|
|
31
|
-
configs.paths.filteredItems = filterItemPath
|
|
32
|
-
setConfig(configs)
|
|
33
|
-
mkdirpSync(filterItemDir)
|
|
34
|
-
writeFileSync(filterItemPath, JSON.stringify(filteredData))
|
|
35
|
-
|
|
36
|
-
return saveFilteredItems(filteredData, 'mocked-name', 'mocked-token').then((output) => {
|
|
37
|
-
expect(output).toBeUndefined()
|
|
38
|
-
}).catch((error) => {
|
|
39
|
-
expect(error).toBeNull()
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
})
|