-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathscopes.test.ts
More file actions
106 lines (89 loc) · 3.5 KB
/
scopes.test.ts
File metadata and controls
106 lines (89 loc) · 3.5 KB
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
102
103
104
105
106
import {allDefaultScopes, apiScopes, tokenExchangeScopes} from './scopes.js'
import {describe, expect, test} from 'vitest'
describe('allDefaultScopes', () => {
// WIP
test('returns all scopes including custom ones', async () => {
// Given
const customScopes = ['custom-scope']
// When
const got = allDefaultScopes(customScopes)
// Then
expect(got).toEqual([
'openid',
'https://api.shopify.com/auth/shop.admin.graphql',
'https://api.shopify.com/auth/shop.admin.themes',
'https://api.shopify.com/auth/partners.collaborator-relationships.readonly',
'https://api.shopify.com/auth/shop.storefront-renderer.devtools',
'https://api.shopify.com/auth/partners.app.cli.access',
'https://api.shopify.com/auth/destinations.readonly',
'https://api.shopify.com/auth/organization.store-management',
'https://api.shopify.com/auth/organization.on-demand-user-access',
'https://api.shopify.com/auth/organization.apps.manage',
...customScopes,
])
})
test('transforms shop-create scope to full URI', async () => {
const got = allDefaultScopes(['shop-create'])
expect(got).toContain('https://api.shopify.com/auth/shop.create')
})
test('includes App Management and Store Management', async () => {
// When
const got = allDefaultScopes([])
// Then
expect(got).toEqual([
'openid',
'https://api.shopify.com/auth/shop.admin.graphql',
'https://api.shopify.com/auth/shop.admin.themes',
'https://api.shopify.com/auth/partners.collaborator-relationships.readonly',
'https://api.shopify.com/auth/shop.storefront-renderer.devtools',
'https://api.shopify.com/auth/partners.app.cli.access',
'https://api.shopify.com/auth/destinations.readonly',
'https://api.shopify.com/auth/organization.store-management',
'https://api.shopify.com/auth/organization.on-demand-user-access',
'https://api.shopify.com/auth/organization.apps.manage',
])
})
})
describe('apiScopes', () => {
// WIP
test('returns all scopes for the given API including custom ones', async () => {
// Given
const customScopes = ['custom-scope']
// When
const got = apiScopes('admin', customScopes)
// Then
expect(got).toEqual([
'https://api.shopify.com/auth/shop.admin.graphql',
'https://api.shopify.com/auth/shop.admin.themes',
'https://api.shopify.com/auth/partners.collaborator-relationships.readonly',
...customScopes,
])
})
})
describe('tokenExchangeScopes', () => {
test('returns transformed scopes for partners API', () => {
// When
const got = tokenExchangeScopes('partners')
// Then
expect(got).toEqual(['https://api.shopify.com/auth/partners.app.cli.access'])
})
test('returns transformed scopes for app-management API', () => {
// When
const got = tokenExchangeScopes('app-management')
// Then
expect(got).toEqual(['https://api.shopify.com/auth/organization.apps.manage'])
})
test('returns transformed scopes for business-platform API', () => {
// When
const got = tokenExchangeScopes('business-platform')
// Then
expect(got).toEqual(['https://api.shopify.com/auth/destinations.readonly'])
})
test('throws an error for unsupported APIs', () => {
// When/Then
expect(() => tokenExchangeScopes('admin')).toThrow('API not supported for token exchange: admin')
expect(() => tokenExchangeScopes('storefront-renderer')).toThrow(
'API not supported for token exchange: storefront-renderer',
)
})
})