forked from camptocamp/ogc-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencoding.spec.ts
More file actions
112 lines (109 loc) · 3.71 KB
/
encoding.spec.ts
File metadata and controls
112 lines (109 loc) · 3.71 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
107
108
109
110
111
112
import { queryXmlDocument } from './http-utils.js';
import { readInfoFromCapabilities } from '../wms/capabilities.js';
import { join } from 'path';
import { readFileSync } from 'fs';
describe('parse XML documents with alternate encodings', () => {
let responseCharset;
beforeAll(() => {
globalThis.fetch = jest.fn((requestInfo) => {
let fileUrl;
if (typeof requestInfo === 'string') fileUrl = requestInfo;
else if (requestInfo instanceof URL) fileUrl = requestInfo.href;
else fileUrl = requestInfo.url;
const pathFromRoot = new URL(fileUrl).pathname;
const filePath = join(__dirname, '../..', pathFromRoot);
const buffer: Buffer = readFileSync(filePath);
const headers = responseCharset
? {
'Content-Type': `application/xml; charset=${responseCharset}`,
}
: {
'Content-Type': 'application/xml',
};
return Promise.resolve({
arrayBuffer: async () => buffer,
status: 200,
ok: true,
headers: new Headers(headers),
clone() {
return this;
},
} as any);
});
});
afterAll(() => {
globalThis.fetch = globalThis.mockFetch;
});
beforeEach(() => {
responseCharset = null;
});
describe('UTF-8 (without header)', () => {
it('successfully parses the XML file', async () => {
const doc = await queryXmlDocument(
'http://localhost:8888/fixtures/wms/capabilities-brgm-1-1-1.xml'
);
expect(readInfoFromCapabilities(doc).title).toBe(
'GéoServices : géologie, hydrogéologie et gravimétrie'
);
});
});
describe('UTF-8 (with header)', () => {
beforeEach(() => {
responseCharset = 'UTF-8';
});
it('successfully parses the XML file', async () => {
const doc = await queryXmlDocument(
'http://localhost:8888/fixtures/wms/capabilities-brgm-1-1-1.xml'
);
expect(readInfoFromCapabilities(doc).title).toBe(
'GéoServices : géologie, hydrogéologie et gravimétrie'
);
});
});
describe('UTF-16 (without header)', () => {
it('successfully parses the XML file', async () => {
const doc = await queryXmlDocument(
'http://localhost:8888/fixtures/wms/capabilities-brgm-1-1-1-utf-16.xml'
);
expect(readInfoFromCapabilities(doc).title).toBe(
'GéoServices : géologie, hydrogéologie et gravimétrie'
);
});
});
describe('UTF-16 (with header)', () => {
beforeEach(() => {
responseCharset = 'UTF-16';
});
it('successfully parses the XML file', async () => {
const doc = await queryXmlDocument(
'http://localhost:8888/fixtures/wms/capabilities-brgm-1-1-1-utf-16.xml'
);
expect(readInfoFromCapabilities(doc).title).toBe(
'GéoServices : géologie, hydrogéologie et gravimétrie'
);
});
});
describe('ISO-8859-15 (without header)', () => {
it('parses the XML file in ISO-8859-1 but misses ISO-8859-15 specific chars', async () => {
const doc = await queryXmlDocument(
'http://localhost:8888/fixtures/wms/capabilities-brgm-1-1-1-iso-8859-15.xml'
);
expect(readInfoFromCapabilities(doc).title).toBe(
'GéoServices : géologie, hydrogéologie et gravimétrie ¤'
);
});
});
describe('ISO-8859-15 (with header)', () => {
beforeEach(() => {
responseCharset = 'ISO-8859-15';
});
it('successfully parses the XML file', async () => {
const doc = await queryXmlDocument(
'http://localhost:8888/fixtures/wms/capabilities-brgm-1-1-1-iso-8859-15.xml'
);
expect(readInfoFromCapabilities(doc).title).toBe(
'GéoServices : géologie, hydrogéologie et gravimétrie €'
);
});
});
});