Skip to content

Commit 766ded5

Browse files
test: api and unit test case for reinstall function
1 parent 73c17c8 commit 766ded5

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

test/api/app-test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { expect } from 'chai'
66

77
dotenv.config()
88

9-
let stack = {}
9+
// let stack = {}
1010
const orgID = process.env.ORG_UID
1111
let client = {}
1212
let appUid = ''
@@ -190,4 +190,17 @@ describe('Apps api Test', () => {
190190
})
191191
.catch(done)
192192
})
193+
194+
it('should reinstall the app', done => {
195+
client.marketplace(orgID).app(appUid).reinstall({ targetType: 'stack', targetUid: process.env.APIKEY })
196+
.then((reinstallation) => {
197+
expect(reinstallation.reinstallation_uid).to.not.equal(undefined)
198+
expect(reinstallation.params.organization_uid).to.be.equal(orgID)
199+
expect(reinstallation.fetch).to.not.equal(undefined)
200+
expect(reinstallation.update).to.not.equal(undefined)
201+
expect(reinstallation.uninstall).to.not.equal(undefined)
202+
done()
203+
})
204+
.catch(done)
205+
})
193206
})

test/unit/apps-test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,38 @@ describe('Contentstack apps test', () => {
303303
done()
304304
})
305305
})
306+
it('should reinstall the app', done => {
307+
const mock = new MockAdapter(Axios)
308+
const uid = appMock.uid
309+
// using same installation mock data for reinstall
310+
mock.onPut(`/manifests/${uid}/reinstall`).reply(200, {
311+
data: {
312+
...installationMock
313+
}
314+
})
315+
const targetUid = 'target_uid'
316+
const targetType = 'target_type'
317+
makeApp({ data: { uid } })
318+
.upgrade({ targetUid, targetType })
319+
.then((reinstallation) => {
320+
expect(reinstallation.status).to.be.equal(installationMock.status)
321+
expect(reinstallation.manifest.name).to.be.equal(installationMock.manifest.name)
322+
expect(reinstallation.target.uid).to.be.equal(installationMock.target.uid)
323+
expect(reinstallation.organization_uid).to.be.equal(installationMock.organization_uid)
324+
expect(reinstallation.uid).to.be.equal(installationMock.uid)
325+
})
326+
.catch(done)
327+
328+
// failing test when empty data is passed
329+
mock.onPut(`/manifests/${uid}/reinstall`).reply(400, {})
330+
makeApp({ data: { uid } })
331+
.upgrade({ targetUid, targetType })
332+
.then()
333+
.catch((error) => {
334+
expect(error).to.not.equal(null)
335+
done()
336+
})
337+
})
306338
})
307339

308340
function checkApp (app) {

0 commit comments

Comments
 (0)