Skip to content

Commit c91d066

Browse files
committed
test: adds test cases for installation functions
1 parent 099aaad commit c91d066

File tree

2 files changed

+134
-5
lines changed

2 files changed

+134
-5
lines changed

test/unit/installation-test.js

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { expect } from 'chai'
33
import { App } from '../../lib/marketplace/app'
44
import { describe, it } from 'mocha'
55
import MockAdapter from 'axios-mock-adapter'
6-
import { appInstallMock, appMock, installationMock } from './mock/objects'
6+
import { appInstallMock, appMock, installationConfigLocationMock, installationMock, installedAppsMock, installedStacksMock, installedUsersMock } from './mock/objects'
77
import { Installation } from '../../lib/marketplace/installation'
8+
import { WebHooks } from '../../lib/marketplace/installation/webhooks'
89

910
describe('Contentstack apps installation test', () => {
1011
it('Installation without installation uid', done => {
@@ -13,27 +14,35 @@ describe('Contentstack apps installation test', () => {
1314
expect(installation.fetch).to.be.equal(undefined)
1415
expect(installation.update).to.be.equal(undefined)
1516
expect(installation.uninstall).to.be.equal(undefined)
16-
expect(installation.findAll).to.be.equal(undefined)
17+
expect(installation.fetchAll).to.be.equal(undefined)
1718
expect(installation.installationData).to.be.equal(undefined)
1819
expect(installation.configuration).to.be.equal(undefined)
1920
expect(installation.setConfiguration).to.be.equal(undefined)
21+
expect(installation.getConfigLocation).to.be.equal(undefined)
2022
expect(installation.serverConfig).to.be.equal(undefined)
2123
expect(installation.setServerConfig).to.be.equal(undefined)
24+
expect(installation.webhooks).to.be.equal(undefined)
2225
done()
2326
})
2427

2528
it('Installation with app uid', done => {
2629
const uid = appMock.uid
27-
const installation = makeInstallation({ app_uid: uid })
28-
expect(installation.urlPath).to.be.equal(undefined)
30+
const installation = makeInstallation({ data: { app_uid: uid } })
31+
expect(installation.urlPath).to.be.equal('/installations')
2932
expect(installation.fetch).to.be.equal(undefined)
3033
expect(installation.update).to.be.equal(undefined)
3134
expect(installation.uninstall).to.be.equal(undefined)
3235
expect(installation.installationData).to.be.equal(undefined)
3336
expect(installation.configuration).to.be.equal(undefined)
3437
expect(installation.setConfiguration).to.be.equal(undefined)
38+
expect(installation.getConfigLocation).to.be.equal(undefined)
3539
expect(installation.serverConfig).to.be.equal(undefined)
3640
expect(installation.setServerConfig).to.be.equal(undefined)
41+
expect(installation.webhooks).to.be.equal(undefined)
42+
expect(installation.fetchAll).to.not.equal(undefined)
43+
expect(installation.getInstalledApps).to.not.equal(undefined)
44+
expect(installation.getInstalledUsers).to.not.equal(undefined)
45+
expect(installation.getInstalledStacks).to.not.equal(undefined)
3746
done()
3847
})
3948

@@ -47,9 +56,14 @@ describe('Contentstack apps installation test', () => {
4756
expect(installation.installationData).to.not.equal(undefined)
4857
expect(installation.configuration).to.not.equal(undefined)
4958
expect(installation.setConfiguration).to.not.equal(undefined)
59+
expect(installation.getConfigLocation).to.not.equal(undefined)
5060
expect(installation.serverConfig).to.not.equal(undefined)
5161
expect(installation.setServerConfig).to.not.equal(undefined)
52-
expect(installation.findAll).to.be.equal(undefined)
62+
expect(installation.webhooks).to.not.equal(undefined)
63+
expect(installation.fetchAll).to.be.equal(undefined)
64+
expect(installation.getInstalledApps).to.be.equal(undefined)
65+
expect(installation.getInstalledUsers).to.be.equal(undefined)
66+
expect(installation.getInstalledStacks).to.be.equal(undefined)
5367
done()
5468
})
5569

@@ -158,6 +172,7 @@ describe('Contentstack apps installation test', () => {
158172
})
159173
.catch(done)
160174
})
175+
161176
it('Set installation configuration test', done => {
162177
const mock = new MockAdapter(Axios)
163178
const uid = installationMock.uid
@@ -173,6 +188,7 @@ describe('Contentstack apps installation test', () => {
173188
})
174189
.catch(done)
175190
})
191+
176192
it('Get installation server config test', done => {
177193
const mock = new MockAdapter(Axios)
178194
const uid = installationMock.uid
@@ -188,6 +204,7 @@ describe('Contentstack apps installation test', () => {
188204
})
189205
.catch(done)
190206
})
207+
191208
it('Get installation installationData test', done => {
192209
const mock = new MockAdapter(Axios)
193210
const uid = installationMock.uid
@@ -232,6 +249,77 @@ describe('Contentstack apps installation test', () => {
232249
})
233250
.catch(done)
234251
})
252+
253+
it('getConfigLocation call should retrieve uilocation configuration details of an installation', done => {
254+
const mock = new MockAdapter(Axios)
255+
const uid = installationConfigLocationMock.uid
256+
mock.onGet(`/installations/${uid}/locations/configuration`).reply(200, {
257+
data: installationConfigLocationMock
258+
})
259+
260+
makeInstallation({ data: { uid } })
261+
.getConfigLocation()
262+
.then((response) => {
263+
expect(response.data).to.be.eql(installationConfigLocationMock)
264+
done()
265+
})
266+
.catch(done)
267+
})
268+
269+
it('should get object of WebHook class when webhooks function is called with uid', () => {
270+
const webHook = makeInstallation({ data: { uid: 'uid' } }).webhooks('webhookUid')
271+
272+
expect(webHook).to.be.instanceOf(WebHooks)
273+
expect(webHook.uid).to.be.equal('webhookUid')
274+
expect(webHook.listExecutionLogs).to.not.equal(undefined)
275+
expect(webHook.getExecutionLog).to.not.equal(undefined)
276+
expect(webHook.retryExecution).to.not.equal(undefined)
277+
})
278+
279+
it('getInstalledApps call should fetch all the installed apps in your Contentstack organization', done => {
280+
const mock = new MockAdapter(Axios)
281+
mock.onGet(`/installations/view/apps`).reply(200, {
282+
data: installedAppsMock
283+
})
284+
285+
makeInstallation({ data: {} })
286+
.getInstalledApps()
287+
.then((response) => {
288+
expect(response.data).to.be.eql(installedAppsMock)
289+
done()
290+
})
291+
.catch(done)
292+
})
293+
294+
it('getInstalledUsers call should fetch all the installed Users in your Contentstack organization', done => {
295+
const mock = new MockAdapter(Axios)
296+
mock.onGet(`/installations/view/users`).reply(200, {
297+
data: installedUsersMock
298+
})
299+
300+
makeInstallation({ data: {} })
301+
.getInstalledUsers()
302+
.then((response) => {
303+
expect(response.data).to.be.eql(installedUsersMock)
304+
done()
305+
})
306+
.catch(done)
307+
})
308+
309+
it('getInstalledStacks call should fetch all the installed Stacks in your Contentstack organization', done => {
310+
const mock = new MockAdapter(Axios)
311+
mock.onGet(`/installations/view/stacks`).reply(200, {
312+
data: installedStacksMock
313+
})
314+
315+
makeInstallation({ data: {} })
316+
.getInstalledStacks()
317+
.then((response) => {
318+
expect(response.data).to.be.eql(installedStacksMock)
319+
done()
320+
})
321+
.catch(done)
322+
})
235323
})
236324

237325
export function checkInstallation (installation) {

test/unit/mock/objects.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,43 @@ const branchMergeQueueFindMock = {
683683
]
684684
}
685685

686+
const installationConfigLocationMock = {
687+
uid: 'Installation_UID',
688+
created_at: '2023-02-28T09:41:01.288Z',
689+
updated_at: '2023-02-28T09:41:01.288Z',
690+
created_by: 'blt22e22222d22d2f22222a2b2f',
691+
updated_by: 'blt22e22222d22d2f22222a2b2f',
692+
tags: [],
693+
ACL: [],
694+
_version: 1,
695+
title: 'App Name',
696+
config: {},
697+
type: 'stack_config_widget',
698+
app_installation_uid: '***REMOVED***',
699+
app_uid: '***REMOVED***',
700+
signed: true,
701+
enable: true,
702+
src: 'http://localhost:3000/config'
703+
}
704+
705+
const installedAppsMock = {
706+
app1: 'data1',
707+
app2: 'data2',
708+
app3: 'data3'
709+
}
710+
711+
const installedUsersMock = {
712+
user1: 'data1',
713+
user2: 'data2',
714+
user3: 'data3'
715+
}
716+
717+
const installedStacksMock = {
718+
stack1: 'data1',
719+
stack2: 'data2',
720+
stack3: 'data3'
721+
}
722+
686723
function mockCollection (mockData, type) {
687724
const mock = {
688725
...cloneDeep(noticeMock),
@@ -751,6 +788,10 @@ export {
751788
branchMergeAllMock,
752789
branchMergeQueueFindMock,
753790
branchMergeQueueFetchMock,
791+
installationConfigLocationMock,
792+
installedAppsMock,
793+
installedUsersMock,
794+
installedStacksMock,
754795
mockCollection,
755796
entryMockCollection,
756797
checkSystemFields

0 commit comments

Comments
 (0)