Skip to content

Commit 31fb2b3

Browse files
committed
feat: 🚧 typedefinition test added with org uid stack implementation [CS-36338]
1 parent 42a59ed commit 31fb2b3

File tree

7 files changed

+194
-7
lines changed

7 files changed

+194
-7
lines changed

test/api/hosting-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ describe('Apps hosting api Test', () => {
5757
it('test deployment for signed upload app hosting', done => {
5858
makeHosting(apps.uid).deployment().findAll()
5959
.then((response) => {
60-
for (const deployment in response.item) {
60+
response.items.forEach(deployment => {
6161
expect(deployment.deployment_number).to.not.equal(undefined)
6262
expect(deployment.deployment_url).to.not.equal(undefined)
6363
expect(deployment.environment).to.not.equal(undefined)
6464
expect(deployment.uid).to.not.equal(undefined)
6565
expect(deployment.urlPath).to.not.equal(undefined)
66-
}
66+
})
6767
done()
6868
})
6969
.catch(done)

test/typescript/app-request.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { expect } from 'chai'
2+
import * as dotenv from 'dotenv'
3+
import { Hosting } from '../../types/app/hosting'
4+
import { Request, Requests } from '../../types/app/request'
5+
dotenv.config()
6+
let requestUID = ''
7+
8+
export function orgAppRequest (request: Requests) {
9+
describe('Org App request api', () => {
10+
test('test get all request for oranization', done => {
11+
request
12+
.findAll()
13+
.then((response) => {
14+
expect(response.data).to.not.equal(undefined)
15+
done()
16+
})
17+
.catch(done)
18+
})
19+
20+
test('test delete app request', done => {
21+
request
22+
.delete(requestUID)
23+
.then((response) => {
24+
expect(response.data).to.not.equal(undefined)
25+
done()
26+
})
27+
.catch(done)
28+
})
29+
})
30+
}
31+
32+
export function appRequest (request: Request) {
33+
describe('App request', () => {
34+
test('test create app request', done => {
35+
request
36+
.create(process.env.APIKEY as string)
37+
.then((response) => {
38+
requestUID = response.data.data.uid
39+
expect(response.data).to.not.equal(undefined)
40+
done()
41+
})
42+
.catch(done)
43+
})
44+
45+
test('test fetch app request', done => {
46+
request
47+
.fetch()
48+
.then((response) => {
49+
expect(response.data).to.not.equal(undefined)
50+
done()
51+
})
52+
.catch(done)
53+
})
54+
})
55+
}

test/typescript/app.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22
import * as dotenv from 'dotenv'
3-
import { AppData, Apps } from '../../types/app'
3+
import { AppData, AppOAuth, Apps } from '../../types/app'
44
import { Organization } from '../../types/organization';
55
dotenv.config()
66
let appUid = ''
@@ -11,14 +11,15 @@ const app: AppData = {
1111
description: 'My new test app',
1212
target_type: 'organization',
1313
}
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'] } }
14+
const config: AppOAuth = { 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'], allow_pkce: true } }
1515

1616
export function createApp(apps: Apps) {
1717
describe('App create', () => {
1818
test('Create App', done => {
1919
apps.create(app)
2020
.then((appResponse) => {
2121
appUid = appResponse.uid
22+
process.env.APP_UID = appResponse.uid
2223
expect(appResponse.uid).to.not.equal(undefined)
2324
expect(appResponse.name).to.be.equal(app.name)
2425
expect(appResponse.description).to.be.equal(app.description)

test/typescript/hosting.ts

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { expect } from 'chai'
2+
import * as dotenv from 'dotenv'
3+
import { Hosting } from '../../types/app/hosting'
4+
dotenv.config()
5+
let uploadUid = ''
6+
let deploymentUid = ''
7+
export function hosting(hosting: Hosting) {
8+
describe('Hosting api', () => {
9+
test('create upload url', done => {
10+
hosting.createUploadUrl()
11+
.then((response)=> {
12+
uploadUid = response.upload_uid
13+
expect(response.upload_uid).to.not.equal(undefined)
14+
expect(response.form_fields).to.not.equal(undefined)
15+
expect(response.upload_url).to.not.equal(undefined)
16+
expect(response.expires_in).to.not.equal(undefined)
17+
done()
18+
})
19+
.catch(done)
20+
})
21+
22+
test('isEnable hosting', done => {
23+
hosting.isEnable()
24+
.then((response) => {
25+
expect(response.enabled).to.not.equal(false)
26+
done()
27+
})
28+
.catch(done)
29+
})
30+
test('test latest live deployment for apps hosting', done => {
31+
hosting.latestLiveDeployment()
32+
.then((response) => {
33+
expect(response).to.not.equal(undefined)
34+
done()
35+
})
36+
.catch(done)
37+
})
38+
39+
test('test enable apps hosting details', done => {
40+
hosting.enable()
41+
.then((response) => {
42+
expect(response.enabled).to.not.equal(true)
43+
done()
44+
})
45+
.catch(done)
46+
})
47+
48+
test('test disable apps hosting details', done => {
49+
hosting.disable()
50+
.then((response) => {
51+
expect(response.enabled).to.not.equal(false)
52+
done()
53+
})
54+
.catch(done)
55+
})
56+
})
57+
}
58+
59+
export function deployment(hosting: Hosting) {
60+
describe('deployment api', () => {
61+
test('create deployment', done => {
62+
hosting.deployment().create({ uploadUid, fileType: 'SOURCE' })
63+
.then((response) => {
64+
deploymentUid = response.uid
65+
expect(response.deployment_number).to.not.equal(undefined)
66+
expect(response.deployment_url).to.not.equal(undefined)
67+
expect(response.environment).to.not.equal(undefined)
68+
expect(response.uid).to.not.equal(undefined)
69+
expect(response.urlPath).to.not.equal(undefined)
70+
done()
71+
})
72+
.catch(done)
73+
})
74+
test('find all deployment', done => {
75+
hosting.deployment().findAll()
76+
.then((response) => {
77+
response.items.forEach(deployment => {
78+
expect(deployment.deployment_number).to.not.equal(undefined)
79+
expect(deployment.deployment_url).to.not.equal(undefined)
80+
expect(deployment.environment).to.not.equal(undefined)
81+
expect(deployment.uid).to.not.equal(undefined)
82+
expect(deployment.urlPath).to.not.equal(undefined)
83+
})
84+
done()
85+
})
86+
.catch(done)
87+
})
88+
test('test get deployment from uid for app hosting', done => {
89+
hosting.deployment(deploymentUid).fetch()
90+
.then((response) => {
91+
expect(response.deployment_number).to.not.equal(undefined)
92+
expect(response.deployment_url).to.not.equal(undefined)
93+
expect(response.environment).to.not.equal(undefined)
94+
expect(response.uid).to.not.equal(undefined)
95+
expect(response.urlPath).to.not.equal(undefined)
96+
done()
97+
})
98+
.catch(done)
99+
})
100+
101+
test('test get deployment logs for app hosting', done => {
102+
hosting.deployment(deploymentUid).logs()
103+
.then((response) => {
104+
for (const i in response) {
105+
const deploymentLogs = response[i]
106+
expect(deploymentLogs.message).to.not.equal(undefined)
107+
expect(deploymentLogs.stage).to.not.equal(undefined)
108+
expect(deploymentLogs.timestamp).to.not.equal(undefined)
109+
}
110+
done()
111+
})
112+
.catch(done)
113+
})
114+
115+
test('test get deployment signed download url for app hosting', done => {
116+
hosting.deployment(deploymentUid).signedDownloadUrl()
117+
.then((response) => {
118+
expect(response.download_url).to.not.equal(undefined)
119+
expect(response.expires_in).to.not.equal(undefined)
120+
done()
121+
})
122+
.catch(done)
123+
})
124+
})
125+
}

test/typescript/index.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { createEnvironment, deleteEnvironment, getEnvironment, updateEnvironment
1414
import { createDeliveryToken, deleteDeliveryToken, deliveryToken, queryDeliveryToken } from './deliveryToken';
1515
import { createRole, findAllRole, getRole, getRoleUid, queryRole } from './role';
1616
import { createApp, deleteApp, fetchApp, installation, updateApp, updateAuth } from './app';
17+
import { deployment, hosting } from './hosting';
18+
import { appRequest, orgAppRequest } from './app-request';
1719
dotenv.config()
1820
jest.setTimeout(10000);
1921

@@ -39,6 +41,10 @@ describe('Typescript API test', () => {
3941
updateApp(org)
4042
updateAuth(org)
4143
installation(org)
44+
hosting(org.app(process.env.APP_UID as string).hosting())
45+
deployment(org.app(process.env.APP_UID as string).hosting())
46+
appRequest(org.app(process.env.APP_UID as string).request())
47+
orgAppRequest(org.app().request())
4248
deleteApp(org)
4349

4450
const stack = client.stack({api_key: process.env.APIKEY as string})

types/app/hosting.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AnyProperty } from '../utility/fields';
1+
import { AnyProperty, SystemFields } from '../utility/fields';
22
import { ContentstackCollection } from '../contentstackCollection'
33
export interface Hosting {
44
isEnable(): Promise<AnyProperty>
@@ -22,7 +22,7 @@ export interface Deployments {
2222
findAll(param?: AnyProperty): Promise<ContentstackCollection<Deployment>>
2323
}
2424

25-
export interface Deployment {
25+
export interface Deployment extends SystemFields {
2626
fetch(): Promise<Deployment>
2727
logs(): Promise<DeploymentLog[]>
2828
signedDownloadUrl(): Promise<DownloadDetails>

types/contentstackClient.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface ContentstackClient {
6161

6262
getUser(params?: Pagination & AnyProperty): Promise<User>
6363

64-
stack(): Queryable<Stack, StackDetails>
64+
stack(query?: {organization_uid?: string}): Queryable<Stack, StackDetails>
6565
stack(config: StackConfig): Stack
6666

6767
organization(): Organizations

0 commit comments

Comments
 (0)