Skip to content
This repository was archived by the owner on May 19, 2020. It is now read-only.

Commit ab2672d

Browse files
authored
Merge pull request #1074 from 18F/lkb-test_user_roles_with_functional_tests
Creating tests for org user role functionality
2 parents 94d0b76 + f9bdd6a commit ab2672d

6 files changed

Lines changed: 409 additions & 436 deletions

File tree

static_src/test/functional/pageobjects/user_role.element.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,35 @@ import BaseElement from './base.element';
99
// TODO attach to class as static property
1010

1111
export default class UserRoleElement extends BaseElement {
12+
// TODO: Look into why "this.element('#org_role' + guid).checked
13+
// does not work. Currently, it doesn't work that way.
14+
setAndGetUserRole(cookieValue) {
15+
this.setUserRole(cookieValue);
16+
return this.getUserRole();
17+
}
1218

19+
setUserRole(cookieValue) {
20+
this.browser.setCookie({ name: 'testing_user_role', value: cookieValue });
21+
this.browser.refresh();
22+
}
23+
24+
getUserRole() {
25+
return this.browser.getCookie('testing_user_role').value;
26+
}
27+
28+
isFirstUserRoleEnabled() {
29+
return this.browser.isEnabled('.test-user-role-control input')[0];
30+
}
31+
32+
isUserOrgManager(guid) {
33+
return !!this.browser.getAttribute(`#org_manager${guid}`, 'checked');
34+
}
35+
36+
isUserBillingManager(guid) {
37+
return !!this.browser.getAttribute(`#billing_manager${guid}`, 'checked');
38+
}
39+
40+
isUserOrgAuditor(guid) {
41+
return !!this.browser.getAttribute(`#org_auditor${guid}`, 'checked');
42+
}
1343
}

static_src/test/functional/user_role.spec.js

Lines changed: 129 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,157 @@
11

2-
describe('User roles', function () {
3-
let cookieResult;
4-
5-
beforeEach(function () {
6-
browser.url('/');
7-
});
2+
import UserRoleElement from './pageobjects/user_role.element';
83

9-
afterEach(function () {
10-
browser.deleteCookie('testing_user_role');
11-
});
4+
describe('User roles', function () {
5+
let cookieResult,
6+
userRoleElement,
7+
cookieValue;
8+
const guidManagerOrgX = 'org-manager-x-uid-601d-48c4-9705',
9+
guidManagerOrgY = 'org-manager-y-uid-601d-48c4-9705',
10+
cookieManagerOrgY = 'org_manager_org_y',
11+
cookieManagerOrgX = 'org_manager_org_x',
12+
cookieManagerSpaceXX = 'space_manager_space_xx',
13+
// cookieManagerSpaceYY = 'space_manager_space_yy',
14+
urlOrgY = '/#/org/user_role-org_y-ffe7-4aa8-8e85-94768d6bd250',
15+
urlOrgX = '/#/org/user_role-org_x-ffe7-4aa8-8e85-94768d6bd250';
1216

1317
describe('User role cookie test', function () {
18+
afterEach(function () {
19+
browser.deleteCookie('testing_user_role');
20+
});
21+
1422
describe('when cookie is set and deleted', function () {
1523
it('should reflect the cookie content', function () {
16-
browser.setCookie({ name: 'testing_user_role', value: 'space_manager_space_xx' });
17-
browser.url('/uaa/userinfo');
24+
browser.url('/');
25+
browser.setCookie({ name: 'testing_user_role', value: cookieManagerSpaceXX });
1826
cookieResult = browser.getCookie('testing_user_role').value;
19-
expect(cookieResult).toBe('space_manager_space_xx');
27+
expect(cookieResult).toBe(cookieManagerSpaceXX);
2028
});
2129
});
2230
});
2331

24-
describe('Org page', function () {
25-
beforeEach(function () {
26-
browser.url('/#/org/user_role-org_x-ffe7-4aa8-8e85-94768d6bd250');
32+
describe('A user on page for orgs', function () {
33+
describe('on page for org X should see only manager X has user permissions', function () {
34+
it('should navigates to org Y', function () {
35+
browser.url(urlOrgX);
36+
37+
browser.waitForExist('.test-users');
38+
userRoleElement = new UserRoleElement(browser, browser.element('.test-users'));
39+
40+
expect(userRoleElement.isVisible()).toBe(true);
41+
});
42+
43+
it('should see manager X has Org Manager access', function () {
44+
expect(userRoleElement.isUserOrgManager(guidManagerOrgX)).toBe(true);
45+
});
46+
47+
it('should see manager Y does not have Org Manager access', function () {
48+
expect(userRoleElement.isUserOrgManager(guidManagerOrgY)).toBe(false);
49+
});
2750
});
2851

29-
it('has a title', function () {
30-
expect(browser.getTitle()).toBe('cloud.gov dashboard');
52+
describe('on page for org Y should see only manager Y has user permissions', function () {
53+
it('should navigates to org Y', function () {
54+
browser.url(urlOrgY);
55+
56+
browser.waitForExist('.test-users');
57+
userRoleElement = new UserRoleElement(browser, browser.element('.test-users'));
58+
59+
expect(userRoleElement.isVisible()).toBe(true);
60+
});
61+
62+
it('should see manager Y has Org Manager access', function () {
63+
expect(userRoleElement.isUserOrgManager(guidManagerOrgY)).toBe(true);
64+
});
65+
66+
it('should see manager X does not have Org Manager access', function () {
67+
expect(userRoleElement.isUserOrgManager(guidManagerOrgX)).toBe(false);
68+
});
3169
});
70+
});
3271

33-
it('has a page header', function () {
34-
browser.waitForExist('.test-page-header-title', 2000);
35-
const pageHeader = browser.element('.test-page-header-title');
36-
expect(pageHeader.getText()).toBe('fake-cf-user_role-org_x-testing');
72+
describe('Testing user roles', function () {
73+
it('Setup userRoleElement', function () {
74+
browser.url(urlOrgX);
75+
browser.waitForExist('.test-users');
76+
userRoleElement = new UserRoleElement(browser, browser.element('.test-users'));
3777
});
3878

39-
describe('org manager for org X then they should', function () {
40-
it('be able to edit roles for org X', function () {
41-
browser.setCookie({ name: 'testing_user_role', value: 'org_manager_org_x' });
42-
cookieResult = browser.getCookie('testing_user_role').value;
43-
expect(cookieResult).toBe('org_manager_org_x');
79+
describe('As org manager Y', function () {
80+
beforeEach(function () {
81+
// sets cookie to org Y manager
82+
cookieValue = cookieManagerOrgY;
83+
});
84+
85+
describe('shouldn\'t have permission to edit fields on org X pages', function () {
86+
it('should set url to org X', function () {
87+
browser.url(urlOrgX);
88+
});
4489

45-
expect(true).toBe(true);
90+
it('verifies that the current user is a user with only permissions to org Y', function () {
91+
cookieResult = userRoleElement.setAndGetUserRole(cookieValue);
92+
expect(cookieResult).toBe(cookieManagerOrgY);
93+
});
94+
95+
it('verify org Y manager cannot modify org X page', function () {
96+
expect(userRoleElement.isFirstUserRoleEnabled()).toBe(false);
97+
});
4698
});
4799

48-
it('not be able to edit roles for org Y', function () {
49-
expect(true).toBe(true);
100+
describe('should have permission to edit fields on org Y pages', function () {
101+
it('should set url to org Y', function () {
102+
browser.url(urlOrgY);
103+
});
104+
105+
it('verifies that the current user is a user with only permissions to org Y', function () {
106+
cookieResult = userRoleElement.setAndGetUserRole(cookieValue);
107+
expect(cookieResult).toBe(cookieManagerOrgY);
108+
});
109+
110+
it('verify org Y manager can modify org Y page', function () {
111+
expect(userRoleElement.isFirstUserRoleEnabled()).toBe(true);
112+
});
50113
});
51114
});
52115

53-
describe('space manager for org X space TT then they should', function () {
54-
it('not be able to edit roles for org X', function () {
55-
expect(true).toBe(true);
116+
describe('As org manager X', function () {
117+
beforeEach(function () {
118+
// sets cookie to org X manager
119+
cookieValue = cookieManagerOrgX;
120+
});
121+
describe('shouldn\'t have permission to edit fields on org Y pages', function () {
122+
it('should set url to org Y', function () {
123+
browser.url(urlOrgY);
124+
});
125+
126+
it('verifies that the current user is a user with only permissions to org X', function () {
127+
cookieResult = userRoleElement.setAndGetUserRole(cookieValue);
128+
expect(cookieResult).toBe(cookieManagerOrgX);
129+
});
130+
131+
it('verify org X manager cannot modify org Y page', function () {
132+
expect(userRoleElement.isFirstUserRoleEnabled()).toBe(false);
133+
});
134+
});
135+
136+
describe('should have permission to edit fields on org X pages', function () {
137+
it('should set url to org X', function () {
138+
browser.url(urlOrgX);
139+
});
140+
141+
it('verifies that the current user is a user with only permissions to org X', function () {
142+
cookieResult = userRoleElement.getUserRole(cookieManagerOrgX);
143+
expect(cookieResult).toBe(cookieManagerOrgX);
144+
});
145+
146+
it('verify org X manager can modify org X page', function () {
147+
expect(userRoleElement.isFirstUserRoleEnabled()).toBe(true);
148+
});
56149
});
57150
});
151+
152+
it('delete cookie after', function () {
153+
browser.deleteCookie('testing_user_role');
154+
});
58155
});
59156

60157
describe('Space page', function () {
@@ -86,7 +183,6 @@ describe('User roles', function () {
86183
});
87184

88185
it('not be able to edit roles for space YY', function () {
89-
expect(true).toBe(true);
90186
});
91187
});
92188
});

static_src/test/server/api.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,12 @@ module.exports = function api(smocks) {
227227
label: 'User organizations',
228228
path: `${BASE_URL}/users/{guid}/organizations`,
229229
handler: function(req, reply) {
230-
reply(MultiResponse(userOrganizations));
230+
const guid = req.params.guid;
231+
let userOrgFlag = 'default';
232+
if(userOrganizations[guid]){
233+
userOrgFlag = guid;
234+
}
235+
reply(MultiResponse(userOrganizations[userOrgFlag]));
231236
}
232237
});
233238

@@ -248,13 +253,11 @@ module.exports = function api(smocks) {
248253
let organizationUserRolesResponse, orgResponseName;
249254
const guid = req.params.guid;
250255
if ( organizationUserRoles[guid] ) {
251-
organizationUserRolesResponse = organizationUserRoles[guid];
252256
orgResponseName = guid;
253257
} else {
254-
organizationUserRolesResponse = organizationUserRoles['default'];
255258
orgResponseName = 'default';
256259
}
257-
reply(MultiResponse(organizationUserRolesResponse));
260+
reply(MultiResponse(organizationUserRoles[orgResponseName]));
258261
}
259262
});
260263

static_src/test/server/fixtures/organization_user_roles.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
11

22
const orgUserRoles = {
3+
"user_role-org_y-ffe7-4aa8-8e85-94768d6bd250": [
4+
{
5+
metadata: {
6+
guid: "org-manager-x-uid-601d-48c4-9705",
7+
url: "/v2/users/org-manager-x-uid-601d-48c4-9705",
8+
created_at: "2015-03-23T22:13:57Z",
9+
updated_at: "2015-03-23T22:13:57Z"
10+
},
11+
entity: {
12+
admin: false,
13+
active: false,
14+
default_space_guid: null,
15+
username: "fake-org-manager-x@gsa.gov",
16+
organization_roles: [
17+
"org_user",
18+
],
19+
spaces_url: "/v2/users/org-manager-x-uid-601d-48c4-9705/spaces",
20+
organizations_url: "/v2/users/org-manager-x-uid-601d-48c4-9705/organizations",
21+
managed_organizations_url: "/v2/users/org-manager-x-uid-601d-48c4-9705/managed_organizations",
22+
billing_managed_organizations_url: "/v2/users/org-manager-x-uid-601d-48c4-9705/billing_managed_organizations",
23+
audited_organizations_url: "/v2/users/org-manager-x-uid-601d-48c4-9705/audited_organizations",
24+
managed_spaces_url: "/v2/users/org-manager-x-uid-601d-48c4-9705/managed_spaces",
25+
audited_spaces_url: "/v2/users/org-manager-x-uid-601d-48c4-9705/audited_spaces"
26+
}
27+
},
28+
{
29+
metadata: {
30+
guid: "org-manager-y-uid-601d-48c4-9705",
31+
url: "/v2/users/org-manager-y-uid-601d-48c4-9705",
32+
created_at: "2015-03-23T22:13:57Z",
33+
updated_at: "2015-03-23T22:13:57Z"
34+
},
35+
entity: {
36+
admin: false,
37+
active: false,
38+
default_space_guid: null,
39+
username: "fake-org-manager-y@gsa.gov",
40+
organization_roles: [
41+
"org_user",
42+
"org_manager",
43+
"org_auditor",
44+
"billing_manager"
45+
],
46+
spaces_url: "/v2/users/org-manager-y-uid-601d-48c4-9705/spaces",
47+
organizations_url: "/v2/users/org-manager-y-uid-601d-48c4-9705/organizations",
48+
managed_organizations_url: "/v2/users/org-manager-y-uid-601d-48c4-9705/managed_organizations",
49+
billing_managed_organizations_url: "/v2/users/org-manager-y-uid-601d-48c4-9705/billing_managed_organizations",
50+
audited_organizations_url: "/v2/users/org-manager-y-uid-601d-48c4-9705/audited_organizations",
51+
managed_spaces_url: "/v2/users/org-manager-y-uid-601d-48c4-9705/managed_spaces",
52+
audited_spaces_url: "/v2/users/org-manager-y-uid-601d-48c4-9705/audited_spaces"
53+
}
54+
},
55+
],
356
"user_role-org_x-ffe7-4aa8-8e85-94768d6bd250": [
457
{
558
metadata: {

0 commit comments

Comments
 (0)