1+ import { expect } from 'chai' ;
2+ import * as dotenv from 'dotenv'
3+ import { AppData , Apps } from '../../types/app'
4+ import { Organization } from '../../types/organization' ;
5+ dotenv . config ( )
6+ let appUid = ''
7+ let installationUid = ''
8+
9+ const app : AppData = {
10+ name : 'My New App' ,
11+ description : 'My new test app' ,
12+ target_type : 'organization' ,
13+ }
14+ const config = { redirect_uri : 'https://example.com/oauth/callback' , app_token_config : { enabled : true , scopes : [ 'scim:manage' ] } , user_token_config : { enabled : true , scopes : [ 'user:read' , 'user:write' , 'scim:manage' ] } }
15+
16+ export function createApp ( apps : Apps ) {
17+ describe ( 'App create' , ( ) => {
18+ test ( 'Create App' , done => {
19+ apps . create ( app )
20+ . then ( ( appResponse ) => {
21+ appUid = appResponse . uid
22+ expect ( appResponse . uid ) . to . not . equal ( undefined )
23+ expect ( appResponse . name ) . to . be . equal ( app . name )
24+ expect ( appResponse . description ) . to . be . equal ( app . description )
25+ expect ( appResponse . target_type ) . to . be . equal ( app . target_type )
26+ done ( )
27+ } )
28+ . catch ( done )
29+ } )
30+ } )
31+ }
32+
33+ export function fetchApp ( organization : Organization ) {
34+ describe ( 'App fetch' , ( ) => {
35+ test ( 'Fetch App' , done => {
36+ organization . app ( appUid ) . fetch ( )
37+ . then ( ( appResponse ) => {
38+ expect ( appResponse . uid ) . to . not . equal ( undefined )
39+ expect ( appResponse . name ) . to . be . equal ( app . name )
40+ expect ( appResponse . description ) . to . be . equal ( app . description )
41+ expect ( appResponse . target_type ) . to . be . equal ( app . target_type )
42+ done ( )
43+ } ) . catch ( done )
44+ } )
45+
46+ test ( 'Find all Apps' , done => {
47+ organization . app ( ) . findAll ( )
48+ . then ( ( apps ) => {
49+ for ( const index in apps . items ) {
50+ const appObject = apps . items [ index ]
51+ expect ( appObject . name ) . to . not . equal ( null )
52+ expect ( appObject . uid ) . to . not . equal ( null )
53+ expect ( appObject . target_type ) . to . not . equal ( null )
54+ }
55+ done ( )
56+ } ) . catch ( done )
57+ } )
58+ } )
59+ }
60+
61+ export function updateApp ( organization : Organization ) {
62+ describe ( 'App update' , ( ) => {
63+ test ( 'Update App' , done => {
64+ const appObj = organization . app ( appUid )
65+ Object . assign ( appObj , { name : 'My Updated App' } )
66+ appObj . update ( )
67+ . then ( ( appResponse ) => {
68+ expect ( appResponse . name ) . to . be . equal ( 'My Updated App' )
69+ expect ( appResponse . description ) . to . be . equal ( app . description )
70+ expect ( appResponse . target_type ) . to . be . equal ( app . target_type )
71+ done ( )
72+ } )
73+ . catch ( done )
74+ } )
75+ } )
76+ }
77+
78+ export function updateAuth ( organization : Organization ) {
79+ describe ( 'App update auth' , ( ) => {
80+ test ( 'Update App auth' , done => {
81+ organization . app ( appUid ) . updateOAuth ( { config} )
82+ . then ( ( appResponse ) => {
83+ expect ( appResponse . redirect_uri ) . to . be . equal ( config . redirect_uri )
84+ expect ( appResponse . app_token_config ! ) . to . deep . equal ( config . app_token_config )
85+ expect ( appResponse . user_token_config ! ) . to . deep . equal ( config . user_token_config )
86+ done ( )
87+ } ) . catch ( done )
88+ } )
89+ } )
90+ describe ( 'App update auth' , ( ) => {
91+ test ( 'Update App auth' , done => {
92+ organization . app ( appUid ) . fetchOAuth ( )
93+ . then ( ( appResponse ) => {
94+ expect ( appResponse . redirect_uri ) . to . be . equal ( config . redirect_uri )
95+ expect ( appResponse . app_token_config ! ) . to . deep . equal ( config . app_token_config )
96+ expect ( appResponse . user_token_config ! ) . to . deep . equal ( config . user_token_config )
97+ done ( )
98+ } ) . catch ( done )
99+ } )
100+ } )
101+ }
102+
103+ export function installation ( organization : Organization ) {
104+ describe ( 'App installation' , ( ) => {
105+ test ( 'Install App' , done => {
106+ organization . app ( appUid ) . install ( { targetType : 'stack' , targetUid : process . env . APIKEY as string } )
107+ . then ( ( installation ) => {
108+ installationUid = installation . uid
109+ expect ( installation . uid ) . to . not . equal ( undefined )
110+ expect ( installation . params . organization_uid ) . to . be . equal ( process . env . ORGANIZATION as string )
111+ expect ( installation . urlPath ) . to . be . equal ( `/installations/${ installation . uid } ` )
112+ expect ( installation . fetch ) . to . not . equal ( undefined )
113+ expect ( installation . update ) . to . not . equal ( undefined )
114+ expect ( installation . uninstall ) . to . not . equal ( undefined )
115+ done ( )
116+ } ) . catch ( done )
117+ } )
118+
119+ test ( 'Get all installations' , done => {
120+ organization . app ( appUid ) . installation ( ) . findAll ( )
121+ . then ( ( installations ) => {
122+ for ( const index in installations . items ) {
123+ const installationObject = installations . items [ index ]
124+ expect ( installationObject . uid ) . to . not . equal ( null )
125+ expect ( installationObject . params . organization_uid ) . to . not . equal ( null )
126+ expect ( installationObject . urlPath ) . to . not . equal ( null )
127+ expect ( installationObject . fetch ) . to . not . equal ( null )
128+ expect ( installationObject . update ) . to . not . equal ( null )
129+ expect ( installationObject . uninstall ) . to . not . equal ( null )
130+ }
131+ done ( )
132+ } ) . catch ( done )
133+ } )
134+
135+ test ( 'Fetch App installation' , done => {
136+ organization . app ( appUid ) . installation ( installationUid ) . fetch ( )
137+ . then ( ( installation ) => {
138+ expect ( installation . uid ) . to . be . equal ( installationUid )
139+ expect ( installation . params . organization_uid ) . to . be . equal ( process . env . ORGANIZATION as string )
140+ expect ( installation . urlPath ) . to . be . equal ( `/installations/${ installation . uid } ` )
141+ expect ( installation . target . type ) . to . be . equal ( 'stack' )
142+ expect ( installation . target . uid ) . to . be . equal ( process . env . APIKEY )
143+ expect ( installation . status ) . to . be . equal ( 'installed' )
144+ done ( )
145+ } ) . catch ( done )
146+ } )
147+
148+ test ( 'Uninstall App installation' , done => {
149+ organization . app ( appUid ) . installation ( installationUid ) . uninstall ( )
150+ . then ( ( installation ) => {
151+ expect ( installation ) . to . deep . equal ( { } )
152+ done ( )
153+ } ) . catch ( done )
154+ } )
155+ } )
156+ }
157+
158+ export function deleteApp ( organization : Organization ) {
159+ describe ( 'App delete' , ( ) => {
160+ test ( 'Delete App' , done => {
161+ organization . app ( appUid ) . delete ( )
162+ . then ( ( appResponse ) => {
163+ expect ( appResponse ) . to . deep . equal ( { } )
164+ done ( )
165+ } ) . catch ( done )
166+ } )
167+ } )
168+ }
0 commit comments