-
Notifications
You must be signed in to change notification settings - Fork 582
/
userAccess.spec.js
101 lines (90 loc) · 4.28 KB
/
userAccess.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import uniqid from "uniqid";
context("Security Users", () => {
it('should verify user access for a "full-access" user', async () => {
let fullAccessGroupUser;
let password = "12345678";
// Create a user with `full-access` group
// eslint-disable-next-line jest/valid-expect-in-promise
cy.securityReadGroup({ slug: "full-access" }).then(group => {
cy.securityCreateUser({
data: {
email: uniqid("", "@gmail.com"),
firstName: uniqid("first name-"),
lastName: uniqid("last name-"),
password,
group: group.id
}
}).then(user => {
fullAccessGroupUser = user;
// Login with new user
cy.login({ username: fullAccessGroupUser.email, password });
cy.visit("/");
// Verify the access
cy.findByText(`Hi ${user.firstName} ${user.lastName}!`).should("be.visible");
cy.findByText(/To get started - pick one of the actions below:/i).should(
"be.visible"
);
// Should have Page Builder card
cy.findByTestId("admin-welcome-screen-widget-page-builder").within(() => {
cy.findByText("Page Builder").should("be.visible");
cy.findByText(/Build a new Page/i).should("be.visible");
});
// Should have Form Builder card
cy.findByTestId("admin-welcome-screen-widget-form-builder").within(() => {
cy.findByText("Form Builder").should("be.visible");
cy.findByText(/Create a new Form/i).should("be.visible");
});
// Should have Headless CMS card
cy.findByTestId("admin-welcome-screen-widget-headless-cms").within(() => {
cy.findByText("Headless CMS").should("be.visible");
cy.findByText(/New content model/i).should("be.visible");
});
// Delete user
// eslint-disable-next-line jest/valid-expect-in-promise
cy.securityDeleteUser({
id: fullAccessGroupUser.id
}).then(data => assert.isTrue(data));
});
});
});
it('should verify user access for a "anonymous" user', () => {
let password = "12345678";
// Create a user with `full-access` group
// eslint-disable-next-line jest/valid-expect-in-promise
cy.securityReadGroup({ slug: "anonymous" }).then(group => {
return cy
.securityCreateUser({
data: {
email: uniqid("", "@gmail.com"),
firstName: uniqid("first name-"),
lastName: uniqid("last name-"),
password,
group: group.id
}
})
.then(user => {
// Login with new user
cy.login({ username: user.email, password });
cy.visit("/");
// Verify the access
cy.findByText(`Hi ${user.firstName} ${user.lastName}!`).should("be.visible");
cy.findByText(
/Please contact the administrator for permissions to access Webiny apps./i
).should("be.visible");
// Should not have Page Builder card
cy.findByTestId("admin-welcome-screen-widget-page-builder").should("not.exist");
// Should not have Form Builder card
cy.findByTestId("admin-welcome-screen-widget-form-builder").should("not.exist");
// Should not have Headless CMS card
cy.findByTestId("admin-welcome-screen-widget-headless-cms").should("not.exist");
// Delete user
// eslint-disable-next-line jest/valid-expect-in-promise
cy.securityDeleteUser({
id: user.id
}).then(data => {
assert.isTrue(data);
});
});
});
});
});