Skip to content

Commit 84ec3bd

Browse files
committed
feat: 🚧 App installation TS API test added
1 parent 97a540b commit 84ec3bd

File tree

7 files changed

+194
-14
lines changed

7 files changed

+194
-14
lines changed

test/api/app-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ describe('Apps api Test', () => {
9494
it('Fetch OAuth app test', done => {
9595
client.organization(orgID).app(appUid).fetchOAuth()
9696
.then((appResponse) => {
97-
appUid = appResponse.uid
9897
expect(appResponse.redirect_uri).to.be.equal(config.redirect_uri)
9998
expect(appResponse.app_token_config.enabled).to.be.equal(config.app_token_config.enabled)
10099
expect(appResponse.user_token_config.enabled).to.be.equal(config.user_token_config.enabled)

test/typescript/app.ts

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
}

test/typescript/index.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,35 @@ import { createLocale, deleteLocale, getLocale } from './locale';
1313
import { createEnvironment, deleteEnvironment, getEnvironment, updateEnvironment } from './environment';
1414
import { createDeliveryToken, deleteDeliveryToken, deliveryToken, queryDeliveryToken } from './deliveryToken';
1515
import { createRole, findAllRole, getRole, getRoleUid, queryRole } from './role';
16+
import { createApp, deleteApp, fetchApp, installation, updateApp, updateAuth } from './app';
1617
dotenv.config()
1718
jest.setTimeout(10000);
1819

1920
const client = Contentstack.client({
2021
authtoken: process.env.AUTHTOKEN,
21-
host: process.env.host,
22+
host: process.env.HOST,
2223
})
2324

2425
describe('Typescript API test', () => {
2526
login(client);
2627
getUser(client)
2728

29+
const org = client.organization(process.env.ORGANIZATION as string)
30+
2831
organizations(client)
29-
organization(client.organization(process.env.ORGANIZATION as string))
32+
organization(org)
3033

3134
stacks(client)
32-
stackTest(client.stack({api_key: process.env.APIKEY}))
35+
stackTest(client.stack({api_key: process.env.APIKEY as string}))
36+
37+
createApp(org.app())
38+
fetchApp(org)
39+
updateApp(org)
40+
updateAuth(org)
41+
installation(org)
42+
deleteApp(org)
3343

34-
const stack = client.stack({api_key: process.env.APIKEY})
44+
const stack = client.stack({api_key: process.env.APIKEY as string})
3545

3646
createBranch(stack)
3747
queryBranch(stack)

test/typescript/stack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import * as dotenv from 'dotenv'
33
import { ContentstackClient } from '../..';
44
import { ContentstackCollection } from '../../types/contentstackCollection';
5-
import { Stack, StackDetails } from '../../types/stack';
5+
import { Stack } from '../../types/stack';
66
dotenv.config()
77

88
var stackName: string

types/app/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { Creatable, SystemFunction } from "../utility/operations";
44
import { Installation, Installations } from "./installation";
55

66
export interface App extends SystemFields, SystemFunction<App> {
7-
fetchOAuth(param: AnyProperty): Promise<{AppOAuth}>
8-
updateOAuth(data: { config: AppOAuth, param: AnyProperty }): Promise<AppOAuth>
7+
fetchOAuth(param?: AnyProperty): Promise<AppOAuth>
8+
updateOAuth(data: { config: AppOAuth, param?: AnyProperty }): Promise<AppOAuth>
99
install(data: {targetUid: string, targetType: AppTarget}): Promise<Installation>
1010
installation(): Installations
1111
installation(uid: string): Installation
1212
}
1313

1414
export interface Apps extends Creatable<App, AppData> {
15-
findAll(param: AnyProperty): Promise<ContentstackCollection<App>>
15+
findAll(param?: AnyProperty): Promise<ContentstackCollection<App>>
1616
}
1717

1818
export interface AppData extends AnyProperty {

types/app/installation.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ContentstackCollection } from "../contentstackCollection";
2-
import { SystemFields } from "../utility/fields";
2+
import { AnyProperty, SystemFields } from "../utility/fields";
33

44
export interface Installation extends SystemFields{
5-
update(param?: AnyProperty): Promise<T>
6-
fetch(param?: AnyProperty): Promise<T>
7-
uninstall(param?: AnyProperty): Promise<T>
5+
update(param?: AnyProperty): Promise<Installation>
6+
fetch(param?: AnyProperty): Promise<Installation>
7+
uninstall(param?: AnyProperty): Promise<AnyProperty>
88
}
99

1010
export interface Installations {
11-
findAll(param: AnyProperty): Promise<ContentstackCollection<Installation>>
11+
findAll(param?: AnyProperty): Promise<ContentstackCollection<Installation>>
1212
}

types/organization.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Sorting } from './utility/sorting'
55
import { Pagination } from './utility/pagination'
66
import { AnyProperty, SystemFields } from './utility/fields'
77
import { ContentstackCollection, Response } from './contentstackCollection'
8+
import { App, Apps } from './app'
89

910
export interface Organizations {
1011
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<Organization>>
@@ -20,6 +21,8 @@ export interface Organization extends SystemFields {
2021
getInvitations(param?: Pagination & AnyProperty): Promise<ContentstackCollection<User>>
2122
resendInvitation(invitationUid: string): Promise<Response>
2223
roles(param?: Pagination & AnyProperty): Promise<ContentstackCollection<Role>>
24+
app(): Apps
25+
app(uid: string): App
2326
}
2427

2528
export interface OrganizationInvite {

0 commit comments

Comments
 (0)