-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathserver.test.ts
More file actions
49 lines (41 loc) · 1.87 KB
/
server.test.ts
File metadata and controls
49 lines (41 loc) · 1.87 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
import {deriveGraphiQLKey, resolveGraphiQLKey} from './server.js'
import {describe, expect, test} from 'vitest'
describe('deriveGraphiQLKey', () => {
test('returns a 64-character hex string', () => {
const key = deriveGraphiQLKey('secret', 'store.myshopify.com')
expect(key).toMatch(/^[0-9a-f]{64}$/)
})
test('is deterministic — same inputs produce the same key', () => {
const key1 = deriveGraphiQLKey('secret', 'store.myshopify.com')
const key2 = deriveGraphiQLKey('secret', 'store.myshopify.com')
expect(key1).toBe(key2)
})
test('different secrets produce different keys', () => {
const key1 = deriveGraphiQLKey('secret-1', 'store.myshopify.com')
const key2 = deriveGraphiQLKey('secret-2', 'store.myshopify.com')
expect(key1).not.toBe(key2)
})
test('different stores produce different keys', () => {
const key1 = deriveGraphiQLKey('secret', 'store-a.myshopify.com')
const key2 = deriveGraphiQLKey('secret', 'store-b.myshopify.com')
expect(key1).not.toBe(key2)
})
})
describe('resolveGraphiQLKey', () => {
test('uses provided key when non-empty', () => {
const key = resolveGraphiQLKey('my-custom-key', 'secret', 'store.myshopify.com')
expect(key).toBe('my-custom-key')
})
test('derives key when provided key is undefined', () => {
const key = resolveGraphiQLKey(undefined, 'secret', 'store.myshopify.com')
expect(key).toBe(deriveGraphiQLKey('secret', 'store.myshopify.com'))
})
test('derives key when provided key is empty string', () => {
const key = resolveGraphiQLKey('', 'secret', 'store.myshopify.com')
expect(key).toBe(deriveGraphiQLKey('secret', 'store.myshopify.com'))
})
test('derives key when provided key is whitespace-only', () => {
const key = resolveGraphiQLKey(' ', 'secret', 'store.myshopify.com')
expect(key).toBe(deriveGraphiQLKey('secret', 'store.myshopify.com'))
})
})