-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (50 loc) · 1.57 KB
/
index.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
export const prng = () =>
`${Math.random().toString(36).substring(2)}${Math.random()
.toString(36)
.substring(2)}`
const isStatusOk = (res) =>
res.ok
? Promise.resolve(res)
: Promise.reject(
new Error(`Received unexpected status code ${res.statusCode}`)
)
export const findEndUserAuthorization = (subject) =>
fetch(
Cypress.env('admin_url') +
'/oauth2/auth/sessions/consent?subject=' +
subject
)
.then(isStatusOk)
.then((res) => res.json())
export const revokeEndUserAuthorization = (subject) =>
fetch(
Cypress.env('admin_url') +
'/oauth2/auth/sessions/consent?subject=' +
subject,
{ method: 'DELETE' }
).then(isStatusOk)
export const createClient = (client) =>
cy
.request('POST', Cypress.env('admin_url') + '/clients', client)
.then(({ body }) =>
getClient(client.client_id).then((actual) => {
if (actual.client_id !== body.client_id) {
return Promise.reject(
new Error(
`Expected client_id's to match: ${actual.client_id} !== ${body.client}`
)
)
}
return Promise.resolve(body)
})
)
export const deleteClients = () =>
cy.request(Cypress.env('admin_url') + '/clients').then(({ body = [] }) => {
;(body || []).forEach(({ client_id }) => deleteClient(client_id))
})
const deleteClient = (client_id) =>
cy.request('DELETE', Cypress.env('admin_url') + '/clients/' + client_id)
const getClient = (id) =>
cy
.request(Cypress.env('admin_url') + '/clients/' + id)
.then(({ body }) => body)