Skip to content

Commit 8b5f827

Browse files
committed
test: ✅ adds CT and GF import test for overwrite flag
1 parent d96f65b commit 8b5f827

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

lib/entity.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ export const publishUnpublish = async (http, url, httpBody, headers, locale = nu
5656
export const upload = async ({ http, urlPath, stackHeaders, formData, params, method = 'POST' }) => {
5757
const headers = {
5858
headers: {
59-
...params,
6059
...cloneDeep(stackHeaders)
60+
},
61+
params: {
62+
...cloneDeep(params)
6163
}
6264
} || {}
63-
6465
if (method === 'POST') {
6566
return http.post(urlPath, formData, headers)
6667
} else {

test/unit/auditLog-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ describe('Contentstack AuditLog test', () => {
3232
makeAuditLog()
3333
.fetchAll()
3434
.then((response) => {
35-
console.log(response);
3635
expect(response.items[0].created_at).to.be.equal('created_at_date')
3736
expect(response.items[0].uid).to.be.equal('UID')
3837
done()

test/unit/contentType-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,31 @@ describe('Contentstack ContentType test', () => {
234234
})
235235
.catch(done)
236236
})
237+
238+
it('ContentType import test with overwrite flag', done => {
239+
var mock = new MockAdapter(Axios)
240+
mock.onPost('/content_types/import').reply(200, {
241+
content_type: {
242+
...contentTypeMock
243+
}
244+
})
245+
const contentTypeUpload = { content_type: path.join(__dirname, '../api/mock/contentType.json') }
246+
const form = createFormData(contentTypeUpload)()
247+
var boundary = form.getBoundary()
248+
249+
expect(boundary).to.be.equal(form.getBoundary())
250+
expect(boundary.length).to.be.equal(50)
251+
makeContentType()
252+
.import(contentTypeUpload, { overwrite: true })
253+
.then((contentType) => {
254+
checkContentType(contentType)
255+
done()
256+
})
257+
.catch((err) => {
258+
console.log('><><><><><><><', err)
259+
done()
260+
})
261+
})
237262
})
238263

239264
function makeContentType (data) {

test/unit/globalField-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,28 @@ describe('Contentstack GlobalField test', () => {
185185
})
186186
.catch(done)
187187
})
188+
189+
it('Global Field import test with overwrite flag', done => {
190+
var mock = new MockAdapter(Axios)
191+
mock.onPost('/global_fields/import').reply(200, {
192+
global_field: {
193+
...globalFieldMock
194+
}
195+
})
196+
const gfUpload = { global_field: path.join(__dirname, '../api/mock/globalfield.json') }
197+
const form = createFormData(gfUpload)()
198+
var boundary = form.getBoundary()
199+
200+
expect(boundary).to.be.equal(form.getBoundary())
201+
expect(boundary.length).to.be.equal(50)
202+
makeGlobalField()
203+
.import(gfUpload, { overwrite: true })
204+
.then((webhook) => {
205+
checkGlobalField(webhook)
206+
done()
207+
})
208+
.catch(done)
209+
})
188210
})
189211

190212
function makeGlobalField (data) {

0 commit comments

Comments
 (0)