Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 955d92a

Browse files
authored
Revert "Remove zen auth"
1 parent 4c150b9 commit 955d92a

27 files changed

+1664
-26
lines changed

.circleci/config.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,17 @@ jobs:
140140
git config --global user.name "CoderDojo Foundation"
141141
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
142142
yarn config set version-git-message "[skip ci] Update to %s" # Skip CI or infinite loop
143-
yarn config set version-commit-hooks false # We're after the tests
143+
yarn config set version-commit-hooks false # We're after the tests
144144
- run:
145145
name: publish to git and npm
146146
command: |
147-
yarn version --patch
147+
yarn version --patch
148148
git push
149149
yarn publish --non-interactive
150-
# disable this for now. 18/05/2020
151-
# - run: {
152-
# "name": "update_platform",
153-
# "command": "sh .circleci/update_platform.sh $(node build/get-version.js) master"
154-
# }
150+
- run: {
151+
"name": "update_platform",
152+
"command": "sh .circleci/update_platform.sh $(node build/get-version.js) master"
153+
}
155154
workflows:
156155
version: 2
157156
build-test-and-deploy:

cypress-e2e.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"integrationFolder": "cypress/integration_e2e",
3+
"baseUrl": "http://localhost:8000",
4+
"video": false
5+
}

cypress-spa-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const app = express();
77
// serve static assets normally
88
app.use(express.static(path.resolve(__dirname, 'dist')));
99

10-
// block known api routes causing looping redirect
11-
app.get(['/rpi/*', '/login', '/logout', '/register'], (request, response) => {
10+
// block known api route causing looping redirect
11+
app.get('/rpi/*', (request, response) => {
1212
response.send('fin.');
1313
});
1414

cypress/fixtures/loginFail.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ok":false,
3+
"why":"invalid-password"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ok":false,
3+
"why":"raspberry-linked"
4+
}

cypress/fixtures/loginSuccess.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ok": true,
3+
"why": "password",
4+
"user": {},
5+
"login": {}
6+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import page from '../../pages/login';
2+
3+
const setupLoggedInServer = () => {
4+
cy.server();
5+
6+
cy.route('POST', '/api/2.0/users/login', 'fx:loginSuccess').as('login');
7+
cy.route('/api/2.0/users/instance', 'fx:parentLoggedIn').as('instance');
8+
cy.route('POST', '/api/2.0/dojos/users', 'fx:userDojosChampion').as(
9+
'userDojosChampion',
10+
);
11+
};
12+
13+
describe('Login Page', () => {
14+
describe('Form Validation', () => {
15+
beforeEach(() => {
16+
cy.server();
17+
cy.route('/api/2.0/users/instance', 'fx:loggedOutUser');
18+
cy.route('/locale/languages', [{ name: 'en', code: 'en_US' }]);
19+
cy.visit('/login');
20+
});
21+
22+
it('should show the header, login box, and all login box elements', () => {
23+
cy.get(page.header).should('be.visible');
24+
cy.get(page.loginBox).should('be.visible');
25+
cy.get(page.email).should('be.visible');
26+
cy.get(page.password).should('be.visible');
27+
cy.get(page.login).should('be.visible');
28+
cy.get(page.forgotPassword).should('be.visible');
29+
cy.get(page.register).should('be.visible');
30+
cy.get(page.forgotPasswordLink).should('have.attr', 'href', '/reset');
31+
cy.get(page.registerLink).should('have.attr', 'href', '/register');
32+
});
33+
34+
it('should show an error when no email is provided on a blur event', () => {
35+
cy.get(page.emailFormatError).should('not.be.visible'); // TODO: Should be emailReqError?
36+
cy.get(page.email).click();
37+
cy.get(page.email)
38+
.invoke('text')
39+
.should('eq', '');
40+
cy.get(page.password).click();
41+
cy.get(page.emailFormatError).should('be.visible');
42+
});
43+
44+
it('should show an error when no password is provided on a blur event', () => {
45+
cy.get(page.passwordReqError).should('not.be.visible');
46+
cy.get(page.password).click();
47+
cy.get(page.password)
48+
.invoke('text')
49+
.should('eq', '');
50+
cy.get(page.loginBox).click();
51+
cy.get(page.passwordReqError).should('be.visible');
52+
});
53+
54+
it('should show an error when the email input is not in the correct format', () => {
55+
cy.get(page.emailFormatError).should('not.be.visible');
56+
cy.get(page.email).click();
57+
cy.get(page.email).type('janedoe');
58+
cy.get(page.password).click();
59+
cy.get(page.emailFormatError).should('be.visible');
60+
});
61+
62+
it('should show an error when the login fails (on mock server this is only when [email protected] email is provided)', () => {
63+
cy.server();
64+
cy.route('POST', '/api/2.0/users/login', 'fx:loginFail').as('loginFail');
65+
cy.get(page.loginFailed).should('not.be.visible');
66+
cy.get(page.email).click();
67+
cy.get(page.email).type('[email protected]');
68+
cy.get(page.password).type('wrongpassword');
69+
cy.get(page.login).click();
70+
cy.wait('@loginFail');
71+
cy.get(page.loginFailed).should('be.visible');
72+
});
73+
74+
it('should show an raspberry linked error when login fails because linked (on mock server this is only when [email protected] email is provided)', () => {
75+
cy.server();
76+
cy.route('POST', '/api/2.0/users/login', 'fx:loginRaspberryFail').as('loginRaspberryFail');
77+
cy.get(page.loginFailed).should('not.be.visible');
78+
cy.get(page.email).click();
79+
cy.get(page.email).type('[email protected]');
80+
cy.get(page.password).type('rightpassword');
81+
cy.get(page.login).click();
82+
cy.wait('@loginRaspberryFail');
83+
cy.get(page.loginRaspberryFailed).should('be.visible');
84+
});
85+
86+
it('should show both requirement errors when a login is attempted if no email and no password is provided', () => {
87+
cy.get(page.emailFormatError).should('not.be.visible'); // TODO: Should be emailReqError?
88+
cy.get(page.passwordReqError).should('not.be.visible');
89+
cy.get(page.login).click();
90+
cy.get(page.emailFormatError).should('be.visible');
91+
cy.get(page.passwordReqError).should('be.visible');
92+
});
93+
94+
it('should show only the email format error when a login is attempted if no password and incorrect form of email is provided', () => {
95+
cy.get(page.emailFormatError).should('not.be.visible');
96+
cy.get(page.email).type('janedoe');
97+
cy.get(page.login).click();
98+
cy.get(page.emailFormatError).should('be.visible');
99+
});
100+
101+
it('should show password requirement error when a login is attempted if no password but an email is provided', () => {
102+
cy.get(page.passwordReqError).should('not.be.visible');
103+
cy.get(page.email).type('[email protected]');
104+
cy.get(page.login).click();
105+
cy.get(page.passwordReqError).should('be.visible');
106+
});
107+
108+
it('should show email requirement error when a login is attempted if no email but a password is provided', () => {
109+
cy.get(page.emailFormatError).should('not.be.visible'); // TODO: Should be emailReqError?
110+
cy.get(page.password).type('test123');
111+
cy.get(page.login).click();
112+
cy.get(page.emailFormatError).should('be.visible');
113+
});
114+
});
115+
116+
describe('Successful Login', () => {
117+
it('should login successfully without a referrer query param', () => {
118+
cy.server();
119+
cy.route('/api/2.0/users/instance', 'fx:loggedOutUser');
120+
cy.route('/locale/languages', [{ name: 'en', code: 'en_US' }]);
121+
cy.visit('/login');
122+
setupLoggedInServer();
123+
cy.get(page.email).type('[email protected]');
124+
cy.get(page.password).type('testparent1');
125+
cy.get(page.login).click();
126+
cy.url().should('include', '/home');
127+
});
128+
129+
it('should login successfully with a referrer query param', () => {
130+
cy.server();
131+
cy.route('/api/2.0/users/instance', 'fx:loggedOutUser');
132+
cy.route('/locale/languages', [{ name: 'en', code: 'en_US' }]);
133+
cy.visit('/login?referrer=%2Fdashboard%2Ftickets');
134+
setupLoggedInServer();
135+
cy.get(page.email).type('[email protected]');
136+
cy.get(page.password).type('testparent1');
137+
cy.get(page.login).click();
138+
cy.url().should('include', '/dashboard/tickets');
139+
});
140+
});
141+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import page from '../../pages/login';
2+
import homePage from '../../pages/home';
3+
4+
describe('Login & out Smoke', () => {
5+
describe('Successful Login & out', () => {
6+
it('should login successfully without a referrer query param', () => {
7+
cy.visit('/login');
8+
cy.get(page.email).type('[email protected]');
9+
cy.get(page.password).type('test');
10+
cy.get(page.login).click();
11+
12+
cy.url().should('include', '/home');
13+
cy.get(homePage.menuUserName).first().invoke('text').should('eq', 'Namey McNameFace');
14+
});
15+
16+
it('should login successfully with a referrer query param', () => {
17+
cy.visit('/login?referrer=%2Fdashboard%2Ftickets');
18+
cy.get(page.email).type('[email protected]');
19+
cy.get(page.password).type('test');
20+
cy.get(page.login).click();
21+
22+
cy.url().should('include', '/dashboard/tickets');
23+
cy.get(homePage.menuUserName).first().invoke('text').should('eq', 'Namey McNameFace');
24+
});
25+
26+
it('should logout successfully', () => {
27+
cy.visit('/login');
28+
cy.get(page.email).type('[email protected]');
29+
cy.get(page.password).type('test');
30+
cy.get(page.login).click();
31+
32+
cy.url().should('include', '/home');
33+
cy.get(homePage.menuUserName).first().click();
34+
cy.get(homePage.menuLogout).first().click();
35+
36+
cy.get(homePage.menuUserName).should('not.be.visible');
37+
});
38+
});
39+
});
40+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import userPage from '../../pages/register-user';
2+
import profilePage from '../../pages/register-profile';
3+
import loginPage from '../../pages/login';
4+
import homePage from '../../pages/home';
5+
6+
const uniqueEmail = `smoke_${String(Math.random()).slice(2)}@test.com`;
7+
const password = 't3stt3st';
8+
9+
describe('Register, login & out Smoke', () => {
10+
it('should register', () => {
11+
cy.visit('/register/user');
12+
13+
cy.get(userPage.firstName).type('Namey');
14+
cy.get(userPage.surname).type('McNameFace');
15+
cy.get(userPage.emailAddress).type(uniqueEmail);
16+
cy.get(userPage.password).type(password);
17+
cy.get(userPage.passConfirmField).type(password);
18+
cy.get(userPage.termsConditionsAccepted).check();
19+
cy.get(userPage.submit).click();
20+
cy.url().should('include', '/register/profile');
21+
22+
cy.get(profilePage.dobCalendarBtn).click();
23+
cy.get(profilePage.yearButton).first().click();
24+
cy.get(profilePage.monthButton).first().click();
25+
cy.get(profilePage.dayButton).first().click();
26+
cy.get(profilePage.countrySelectOpen).click();
27+
cy.get(profilePage.countryInput).type('united kingdom');
28+
cy.get(profilePage.countryOption).first().click();
29+
cy.wait(5000); // Click the recaptcha!
30+
cy.get(profilePage.submit).click();
31+
32+
cy.url().should('include', '/home');
33+
cy.get(homePage.menuUserName).first().invoke('text').should('eq', 'Namey McNameFace');
34+
});
35+
it('should logout', () => {
36+
cy.get(homePage.menuUserName).first().click();
37+
cy.get(homePage.menuLogout).first().click();
38+
39+
cy.get(homePage.menuUserName).should('not.be.visible');
40+
});
41+
it('should login', () => {
42+
cy.visit('/login');
43+
cy.get(loginPage.email).type(uniqueEmail);
44+
cy.get(loginPage.password).type(password);
45+
cy.get(loginPage.login).click();
46+
47+
cy.url().should('include', '/home');
48+
cy.get(homePage.menuUserName).first().invoke('text').should('eq', 'Namey McNameFace');
49+
});
50+
});
51+

cypress/pages/login.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
header: '.cd-login__header',
3+
loginBox: '.cd-login__box',
4+
email: 'input[type=email]',
5+
password: 'input[type=password]',
6+
login: 'input[type=submit]',
7+
register: '.cd-login__register',
8+
forgotPassword: '.cd-login__forgot-password',
9+
emailReqError: '.cd-login__email-req-err',
10+
emailFormatError: '.cd-login__email-format-err',
11+
passwordReqError: '.cd-login__password-req-err',
12+
loginFailed: '.cd-login__login-failed',
13+
loginRaspberryFailed: '.cd-login__raspberry-linked',
14+
registerLink: '.cd-login__register a',
15+
forgotPasswordLink: '.cd-login__forgot-password a',
16+
};

0 commit comments

Comments
 (0)