-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample.spec.js
56 lines (50 loc) · 1.6 KB
/
example.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
const client_id = 'wLSIP47wM39wKdDmOj6Zb5eSEw3JVhVp';
const client_secret = '';
const audience = 'https://brucke.auth0.com/api/v2/';
const scope = 'openid profile email';
const username = '';
const password = '';
context('Example', () => {
it('should be logged in', () => {
cy.clearLocalStorage();
cy.log('getting tokens');
cy.request({
method: 'POST',
url: 'https://brucke.auth0.com/oauth/token',
body: {
grant_type: 'password',
username,
password,
audience,
scope,
client_id,
client_secret,
},
}).then(({ body: { access_token, expires_in, id_token, token_type } }) => {
cy.visit('http://localhost:3000');
cy.get('#btn').should('be.visible');
cy.get('#hello').should('not.be.visible');
cy.window().then((win) => {
win.localStorage.setItem(
`@@auth0spajs@@::${client_id}::${audience}::${scope}`, // Could also be ::default:: instead of ::${audience}::
JSON.stringify({
body: {
client_id,
access_token,
id_token,
scope,
expires_in,
token_type,
decodedToken: { user: JSON.parse(Buffer.from(id_token.split('.')[1], 'base64').toString('ascii')) },
audience
},
expiresAt: Math.floor(Date.now() / 1000) + expires_in
})
)
})
cy.visit('http://localhost:3000');
cy.get('#btn').should('not.be.visible');
cy.get('#hello').should('contain', `Hello ${username}`);
});
})
})