@@ -3,8 +3,9 @@ import { expect } from 'chai'
33import { App } from '../../lib/marketplace/app'
44import { describe , it } from 'mocha'
55import 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'
77import { Installation } from '../../lib/marketplace/installation'
8+ import { WebHooks } from '../../lib/marketplace/installation/webhooks'
89
910describe ( '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
237325export function checkInstallation ( installation ) {
0 commit comments