-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelpers.test.js
More file actions
69 lines (62 loc) · 1.81 KB
/
Copy pathhelpers.test.js
File metadata and controls
69 lines (62 loc) · 1.81 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
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { fetchContentAndMetadata, getResponseMetadata } from '../src/resourceLoader.ts'
describe('resourceLoader', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('reads response headers into metadata', () => {
const response = {
headers: {
get: vi.fn((name) => {
if (name === 'content-type') return 'text/turtle; charset=utf-8'
if (name === 'wac-allow') return 'user="write", public="read"'
if (name === 'etag') return '"abc"'
return null
})
}
}
const store = {
each: vi.fn(),
any: vi.fn(),
anyValue: vi.fn(() => undefined),
sym: vi.fn()
}
const subject = { uri: 'https://example.org/profile/card' }
expect(getResponseMetadata(store, subject, response)).toEqual({
contentType: 'text/turtle',
eTag: '"abc"'
})
})
it('fetches content and applies the returned metadata', async () => {
const response = {
ok: true,
headers: {
get: vi.fn((name) => {
if (name === 'content-type') return 'text/turtle'
if (name === 'wac-allow') return 'user="write", public="read"'
if (name === 'etag') return '"abc"'
return null
})
},
responseText: '<> a <#Thing>.'
}
const store = {
fetcher: {
webOperation: vi.fn().mockResolvedValue(response)
},
each: vi.fn(),
any: vi.fn(),
anyValue: vi.fn(() => undefined),
sym: vi.fn()
}
const subject = { uri: 'https://example.org/profile/card' }
const result = await fetchContentAndMetadata(store, subject)
expect(result).toEqual({
content: '<> a <#Thing>.',
metadata: {
contentType: 'text/turtle',
eTag: '"abc"'
}
})
})
})