Skip to content

Commit b70849b

Browse files
Merge pull request #128 from contentstack/test/cs-43501-sanity-test-teams-stack-share
sanity test teams stack share
2 parents 45b3e76 + 6444453 commit b70849b

File tree

11 files changed

+269
-22
lines changed

11 files changed

+269
-22
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/mock/branch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const branch = {
44
}
55

66
const stageBranch = {
7-
uid: 'staging',
7+
uid: 'staging1',
88
source: 'main'
99
}
1010

1111
const devBranch = {
12-
uid: 'merge_test',
13-
source: 'staging'
12+
uid: 'test_merge',
13+
source: 'staging1'
1414
}
1515

1616
export {

test/sanity-check/mock/deliveryToken.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const createDeliveryToken = {
1616
module: 'branch',
1717
branches: [
1818
'main',
19-
'staging'
19+
'staging1'
2020
],
2121
acl: {
2222
read: true
@@ -25,7 +25,7 @@ const createDeliveryToken = {
2525
{
2626
module: 'branch_alias',
2727
branch_aliases: [
28-
'staging_alias'
28+
'staging1_alias'
2929
],
3030
acl: {
3131
read: true
@@ -52,7 +52,7 @@ const createDeliveryToken2 = {
5252
module: 'branch',
5353
branches: [
5454
'main',
55-
'staging'
55+
'staging1'
5656
],
5757
acl: {
5858
read: true
@@ -61,7 +61,7 @@ const createDeliveryToken2 = {
6161
{
6262
module: 'branch_alias',
6363
branch_aliases: [
64-
'staging_alias'
64+
'staging1_alias'
6565
],
6666
acl: {
6767
read: true

test/sanity-check/mock/managementToken.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const createManagementToken = {
2222
{
2323
module: 'branch_alias',
2424
branch_aliases: [
25-
'sb1_alias'
25+
'staging1_alias'
2626
],
2727
acl: {
2828
read: true
@@ -57,7 +57,7 @@ const createManagementToken2 = {
5757
{
5858
module: 'branch_alias',
5959
branch_aliases: [
60-
'sb1_alias'
60+
'staging1_alias'
6161
],
6262
acl: {
6363
read: true

test/sanity-check/mock/role.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const role = {
1515
{
1616
module: 'branch_alias',
1717
branch_aliases: [
18-
'staging_alias'
18+
'staging1_alias'
1919
],
2020
acl: {
2121
read: true

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')

test/typescript/teamUsers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ export function testTeamUsers (organization: Organization) {
2525
test('should fetch all users', done => {
2626
organization.teams(teamUid).teamUsers()
2727
.fetchAll()
28-
.then((response) => {
29-
expect(response.items[0]).not.to.be.equal(undefined)
30-
done()
28+
.then((users) => {
29+
users.items.forEach((user) => {
30+
expect(user.userId).to.be.not.equal(null)
3131
})
32+
done()
33+
})
3234
.catch(done)
3335
})
3436
})

test/unit/team-users-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Contentstack Team Users test', () => {
1212
makeTeamUsers().fetchAll()
1313
.then((users) => {
1414
users.items.forEach((user) => {
15-
expect(user.uidId).to.be.not.equal(null)
15+
expect(user.userId).to.be.not.equal(null)
1616
})
1717
done()
1818
})

0 commit comments

Comments
 (0)