Skip to content

Commit b55ac30

Browse files
test: added teams and stack share test suit to sanity
1 parent 60c1b95 commit b55ac30

File tree

4 files changed

+247
-3
lines changed

4 files changed

+247
-3
lines changed

lib/organization/teams/teamUsers/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export function TeamUsers (http, data) {
6464
}
6565
}
6666
export function UsersCollection (http, data) {
67-
const obj = cloneDeep(data.teamUsers) || []
68-
const usersCollection = obj.map((user) => {
69-
return new TeamUsers(http, { userId: user })
67+
const obj = cloneDeep(data.users) || []
68+
const usersCollection = obj.map((userId) => {
69+
return new TeamUsers(http, { userId })
7070
})
7171
return usersCollection
7272
}

test/sanity-check/api/stack-share.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { expect } from 'chai'
2+
import { describe, it, setup } from 'mocha'
3+
import { jsonReader } from '../utility/fileOperations/readwrite'
4+
import { contentstackClient } from '../utility/ContentstackClient.js'
5+
import dotenv from 'dotenv'
6+
7+
dotenv.config()
8+
var client = {}
9+
10+
describe('Stack Share/Unshare', () => {
11+
setup(() => {
12+
const user = jsonReader('loggedinuser.json')
13+
client = contentstackClient(user.authtoken)
14+
})
15+
it('should share stack test', done => {
16+
const role = jsonReader('roles.json')
17+
client.stack({ api_key: process.env.API_KEY })
18+
.share(['[email protected]'], { '[email protected]': [role[0].uid] })
19+
.then((response) => {
20+
expect(response.notice).to.be.equal('The invitation has been sent successfully.')
21+
done()
22+
})
23+
.catch(done)
24+
})
25+
26+
it('should unshare stack test', done => {
27+
client.stack({ api_key: process.env.API_KEY })
28+
.unShare('[email protected]')
29+
.then((response) => {
30+
expect(response.notice).to.be.equal('The stack has been successfully unshared.')
31+
done()
32+
})
33+
.catch(done)
34+
})
35+
})

test/sanity-check/api/team-test.js

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
import { describe, it, beforeEach } from 'mocha'
2+
import { expect } from 'chai'
3+
import { jsonReader } from '../utility/fileOperations/readwrite'
4+
import { contentstackClient } from '../utility/ContentstackClient.js'
5+
import dotenv from 'dotenv'
6+
7+
dotenv.config()
8+
let client = {}
9+
10+
const organizationUid = process.env.ORGANIZATION
11+
const stackApiKey = process.env.API_KEY
12+
let userId = ''
13+
let teamUid1 = ''
14+
let teamUid2 = ''
15+
let orgRole1 = ''
16+
let stackRole1 = ''
17+
let stackRole2 = ''
18+
let stackRole3 = ''
19+
20+
describe('Teams API Test', () => {
21+
beforeEach(() => {
22+
const user = jsonReader('loggedinuser.json')
23+
client = contentstackClient(user.authtoken)
24+
const orgRoles = jsonReader('orgRoles.json')
25+
orgRole1 = orgRoles[0].uid
26+
})
27+
28+
it('should create new team 1 when required object is passed', async () => {
29+
const response = await makeTeams().create({
30+
name: 'test_team1',
31+
users: [],
32+
stackRoleMapping: [],
33+
organizationRole: orgRole1 })
34+
teamUid1 = response.uid
35+
expect(response.uid).not.to.be.equal(null)
36+
expect(response.name).not.to.be.equal(null)
37+
expect(response.stackRoleMapping).not.to.be.equal(null)
38+
expect(response.organizationRole).not.to.be.equal(null)
39+
})
40+
41+
it('should create new team 2 when required object is passed', async () => {
42+
const response = await makeTeams().create({
43+
name: 'test_team2',
44+
users: [],
45+
stackRoleMapping: [],
46+
organizationRole: orgRole1 })
47+
teamUid2 = response.uid
48+
expect(response.uid).not.to.be.equal(null)
49+
expect(response.name).not.to.be.equal(null)
50+
expect(response.stackRoleMapping).not.to.be.equal(null)
51+
expect(response.organizationRole).not.to.be.equal(null)
52+
})
53+
54+
it('should get all the teams when correct organization uid is passed', async () => {
55+
const response = await makeTeams().fetchAll()
56+
expect(response.items[0].organizationUid).to.be.equal(organizationUid)
57+
expect(response.items[0].name).not.to.be.equal(null)
58+
expect(response.items[0].created_by).not.to.be.equal(null)
59+
expect(response.items[0].updated_by).not.to.be.equal(null)
60+
})
61+
62+
it('should fetch the team when team uid is passed', async () => {
63+
const response = await makeTeams(teamUid1).fetch()
64+
expect(response.uid).to.be.equal(teamUid1)
65+
expect(response.organizationUid).to.be.equal(organizationUid)
66+
expect(response.name).not.to.be.equal(null)
67+
expect(response.created_by).not.to.be.equal(null)
68+
expect(response.updated_by).not.to.be.equal(null)
69+
})
70+
71+
it('should update team when updating data is passed', async () => {
72+
const updateData = {
73+
name: 'name',
74+
users: [
75+
{
76+
email: process.env.EMAIL
77+
}
78+
],
79+
organizationRole: orgRole1,
80+
stackRoleMapping: []
81+
}
82+
await makeTeams(teamUid1).update(updateData)
83+
.then((team) => {
84+
expect(team.name).to.be.equal(updateData.name)
85+
expect(team.createdByUserName).not.to.be.equal(undefined)
86+
expect(team.updatedByUserName).not.to.be.equal(undefined)
87+
})
88+
})
89+
90+
it('should delete team 1 when team uid is passed', async () => {
91+
const response = await makeTeams(teamUid1).delete()
92+
expect(response.status).to.be.equal(204)
93+
})
94+
})
95+
96+
describe('Teams Stack Role Mapping API Test', () => {
97+
beforeEach(() => {
98+
const user = jsonReader('loggedinuser.json')
99+
client = contentstackClient(user.authtoken)
100+
const stackRoles = jsonReader('roles.json')
101+
stackRole1 = stackRoles[0].uid
102+
stackRole2 = stackRoles[1].uid
103+
stackRole3 = stackRoles[2].uid
104+
})
105+
106+
it('should add roles', done => {
107+
const stackRoleMappings = {
108+
stackApiKey: stackApiKey,
109+
roles: [
110+
stackRole1
111+
]
112+
}
113+
makestackRoleMappings(teamUid2).add(stackRoleMappings).then((response) => {
114+
expect(response.stackRoleMapping).not.to.be.equal(undefined)
115+
expect(response.stackRoleMapping.roles[0]).to.be.equal(stackRoleMappings.roles[0])
116+
expect(response.stackRoleMapping.stackApiKey).to.be.equal(stackRoleMappings.stackApiKey)
117+
done()
118+
})
119+
.catch(done)
120+
})
121+
122+
it('should fetch all stackRoleMappings', done => {
123+
makestackRoleMappings(teamUid2).fetchAll().then((response) => {
124+
expect(response.stackRoleMappings).to.be.not.equal(undefined)
125+
done()
126+
})
127+
.catch(done)
128+
})
129+
130+
it('should update roles', done => {
131+
const stackRoleMappings = {
132+
roles: [
133+
stackRole1,
134+
stackRole2,
135+
stackRole3
136+
]
137+
}
138+
makestackRoleMappings(teamUid2, stackApiKey).update(stackRoleMappings).then((response) => {
139+
expect(response.stackRoleMapping).not.to.be.equal(undefined)
140+
expect(response.stackRoleMapping.roles[0]).to.be.equal(stackRoleMappings.roles[0])
141+
expect(response.stackRoleMapping.stackApiKey).to.be.equal(stackApiKey)
142+
done()
143+
})
144+
.catch(done)
145+
})
146+
147+
it('should delete roles', done => {
148+
makestackRoleMappings(teamUid2, stackApiKey).delete().then((response) => {
149+
expect(response.status).to.be.equal(204)
150+
done()
151+
})
152+
.catch(done)
153+
})
154+
})
155+
156+
describe('Teams Users API Test', () => {
157+
beforeEach(() => {
158+
const user = jsonReader('loggedinuser.json')
159+
client = contentstackClient(user.authtoken)
160+
})
161+
it('should add the user when user\'s mail is passed', done => {
162+
const usersMail = {
163+
emails: ['[email protected]']
164+
}
165+
makeUsers(teamUid2).add(usersMail).then((response) => {
166+
expect(response.status).to.be.equal(201)
167+
done()
168+
})
169+
.catch(done)
170+
})
171+
172+
it('should fetch all users', done => {
173+
makeUsers(teamUid2).fetchAll().then((response) => {
174+
response.items.forEach((user) => {
175+
userId = response.items[0].userId
176+
expect(user.userId).to.be.not.equal(null)
177+
done()
178+
})
179+
})
180+
.catch(done)
181+
})
182+
183+
it('should remove the user when uid is passed', done => {
184+
makeUsers(teamUid2, userId).remove().then((response) => {
185+
expect(response.status).to.be.equal(204)
186+
done()
187+
})
188+
.catch(done)
189+
})
190+
191+
it('should delete team 2 when team uid is passed', async () => {
192+
const response = await makeTeams(teamUid2).delete()
193+
expect(response.status).to.be.equal(204)
194+
})
195+
})
196+
197+
function makeTeams (teamUid = null) {
198+
return client.organization(organizationUid).teams(teamUid)
199+
}
200+
201+
function makestackRoleMappings (teamUid, stackApiKey = null) {
202+
return client.organization(organizationUid).teams(teamUid).stackRoleMappings(stackApiKey)
203+
}
204+
205+
function makeUsers (teamUid, userId = null) {
206+
return client.organization(organizationUid).teams(teamUid).teamUsers(userId)
207+
}

test/sanity-check/sanity.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require('./api/user-test')
22
require('./api/organization-test')
33
require('./api/stack-test')
4+
require('./api/stack-share')
45
require('./api/locale-test')
56
require('./api/environment-test')
67
require('./api/branch-test')
@@ -21,3 +22,4 @@ require('./api/contentType-delete-test')
2122
require('./api/taxonomy-test')
2223
require('./api/terms-test')
2324
require('./api/delete-test')
25+
require('./api/team-test')

0 commit comments

Comments
 (0)