@@ -12,6 +12,7 @@ describe('Contentstack apps test', () => {
1212 expect ( app . urlPath ) . to . be . equal ( '/manifests' )
1313 expect ( app . create ) . to . not . equal ( undefined )
1414 expect ( app . findAll ) . to . not . equal ( undefined )
15+ expect ( app . findAllAuthorized ) . to . not . equal ( undefined )
1516 expect ( app . fetch ) . to . be . equal ( undefined )
1617 expect ( app . update ) . to . be . equal ( undefined )
1718 expect ( app . delete ) . to . be . equal ( undefined )
@@ -20,6 +21,8 @@ describe('Contentstack apps test', () => {
2021 expect ( app . hosting ) . to . be . equal ( undefined )
2122 expect ( app . install ) . to . be . equal ( undefined )
2223 expect ( app . installation ) . to . be . equal ( undefined )
24+ expect ( app . getRequests ) . to . be . equal ( undefined )
25+ expect ( app . authorize ) . to . be . equal ( undefined )
2326 done ( )
2427 } )
2528
@@ -29,6 +32,7 @@ describe('Contentstack apps test', () => {
2932 expect ( app . urlPath ) . to . be . equal ( `/manifests/${ uid } ` )
3033 expect ( app . create ) . to . be . equal ( undefined )
3134 expect ( app . findAll ) . to . be . equal ( undefined )
35+ expect ( app . findAllAuthorized ) . to . be . equal ( undefined )
3236 expect ( app . fetch ) . to . not . equal ( undefined )
3337 expect ( app . update ) . to . not . equal ( undefined )
3438 expect ( app . delete ) . to . not . equal ( undefined )
@@ -37,6 +41,8 @@ describe('Contentstack apps test', () => {
3741 expect ( app . hosting ) . to . not . equal ( undefined )
3842 expect ( app . install ) . to . not . equal ( undefined )
3943 expect ( app . installation ) . to . not . equal ( undefined )
44+ expect ( app . getRequests ) . to . not . equal ( undefined )
45+ expect ( app . authorize ) . to . not . equal ( undefined )
4046 expect ( app . hosting ( ) ) . to . not . equal ( undefined )
4147 expect ( app . installation ( ) ) . to . not . equal ( undefined )
4248 expect ( app . installation ( uid ) ) . to . not . equal ( undefined )
@@ -50,6 +56,7 @@ describe('Contentstack apps test', () => {
5056 expect ( app . urlPath ) . to . be . equal ( `/manifests/${ uid } ` )
5157 expect ( app . create ) . to . be . equal ( undefined )
5258 expect ( app . findAll ) . to . be . equal ( undefined )
59+ expect ( app . findAllAuthorized ) . to . be . equal ( undefined )
5360 expect ( app . fetch ) . to . not . equal ( undefined )
5461 expect ( app . update ) . to . not . equal ( undefined )
5562 expect ( app . delete ) . to . not . equal ( undefined )
@@ -58,6 +65,8 @@ describe('Contentstack apps test', () => {
5865 expect ( app . hosting ) . to . not . equal ( undefined )
5966 expect ( app . install ) . to . not . equal ( undefined )
6067 expect ( app . installation ) . to . not . equal ( undefined )
68+ expect ( app . getRequests ) . to . not . equal ( undefined )
69+ expect ( app . authorize ) . to . not . equal ( undefined )
6170 done ( )
6271 } )
6372
@@ -146,6 +155,38 @@ describe('Contentstack apps test', () => {
146155 . catch ( done )
147156 } )
148157
158+ it ( 'Get all authorized apps in organization test' , done => {
159+ const content = {
160+ visibility : 'private' ,
161+ description : 'This is a test App.' ,
162+ name : 'New App' ,
163+ org_id : 'org_uid' ,
164+ created_at : '2021-07-20T13:34:54.791Z' ,
165+ updated_at : '2021-07-27T14:05:19.452Z' ,
166+ id : 'id'
167+ }
168+ const mock = new MockAdapter ( Axios )
169+ mock . onGet ( `/authorized-apps` ) . reply ( 200 , {
170+ data : [
171+ content
172+ ]
173+ } )
174+
175+ makeApp ( { } )
176+ . findAllAuthorized ( )
177+ . then ( ( response ) => {
178+ expect ( response . data [ 0 ] . visibility ) . to . be . equal ( content . visibility )
179+ expect ( response . data [ 0 ] . description ) . to . be . equal ( content . description )
180+ expect ( response . data [ 0 ] . name ) . to . be . equal ( content . name )
181+ expect ( response . data [ 0 ] . org_id ) . to . be . equal ( content . org_id )
182+ expect ( response . data [ 0 ] . created_at ) . to . be . equal ( content . created_at )
183+ expect ( response . data [ 0 ] . updated_at ) . to . be . equal ( content . updated_at )
184+ expect ( response . data [ 0 ] . id ) . to . be . equal ( content . id )
185+ done ( )
186+ } )
187+ . catch ( done )
188+ } )
189+
149190 it ( 'Get oAuth configuration test' , done => {
150191 const mock = new MockAdapter ( Axios )
151192 const uid = appMock . uid
@@ -231,6 +272,36 @@ describe('Contentstack apps test', () => {
231272 } )
232273 . catch ( done )
233274 } )
275+ it ( 'test authorize app' , ( done ) => {
276+ const uid = appMock . uid
277+ const mock = new MockAdapter ( Axios )
278+ mock . onPost ( `/manifests/${ appMock . uid } /authorize` ) . reply ( 200 , {
279+ data : { redirect_uri : 'uri' }
280+ } )
281+
282+ makeApp ( { data : { uid } } )
283+ . authorize ( { responseType : 'type' , clientId : 'id' , redirectUri : 'uri' , scope : 'scope' } )
284+ . then ( ( response ) => {
285+ expect ( response . data . redirect_uri ) . to . be . equal ( 'uri' )
286+ done ( )
287+ } )
288+ . catch ( done )
289+ } )
290+ it ( 'test authorize app fail request' , ( done ) => {
291+ const uid = appMock . uid
292+ const mock = new MockAdapter ( Axios )
293+ mock . onPost ( `/manifests/${ appMock . uid } /authorize` ) . reply ( 400 , {
294+
295+ } )
296+
297+ makeApp ( { data : { uid } } )
298+ . authorize ( { state : 'state' , responseType : 'type' , clientId : 'id' , redirectUri : 'uri' , scope : 'scope' } )
299+ . then ( done )
300+ . catch ( ( error ) => {
301+ expect ( error ) . to . not . equal ( undefined )
302+ done ( )
303+ } )
304+ } )
234305 it ( 'test fetch request for app uid fail request' , ( done ) => {
235306 const uid = appMock . uid
236307 const mock = new MockAdapter ( Axios )
@@ -246,6 +317,35 @@ describe('Contentstack apps test', () => {
246317 done ( )
247318 } )
248319 } )
320+ it ( 'test authorize app fail request' , ( done ) => {
321+ const uid = appMock . uid
322+ const mock = new MockAdapter ( Axios )
323+ mock . onPost ( `/manifests/${ appMock . uid } /requests` ) . reply ( 400 , {
324+
325+ } )
326+
327+ makeApp ( { data : { uid } } )
328+ . getRequests ( )
329+ . then ( done )
330+ . catch ( ( error ) => {
331+ expect ( error ) . to . not . equal ( undefined )
332+ done ( )
333+ } )
334+ } )
335+ it ( 'Get all authorized apps in organization fail request' , done => {
336+ const mock = new MockAdapter ( Axios )
337+ mock . onGet ( `/authorized-apps` ) . reply ( 400 , {
338+
339+ } )
340+
341+ makeApp ( { } )
342+ . findAllAuthorized ( )
343+ . then ( done )
344+ . catch ( ( error ) => {
345+ expect ( error ) . to . not . equal ( undefined )
346+ done ( )
347+ } )
348+ } )
249349} )
250350
251351function checkApp ( app ) {
0 commit comments