-
Notifications
You must be signed in to change notification settings - Fork 10
/
e2e-tests.ts
51 lines (45 loc) · 1.65 KB
/
e2e-tests.ts
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
import { ContentClient } from './build/main/index';
const CONTENT_ID = '4cef6e46-95a3-48a6-8202-e31871eaaa72' as const;
const CONTENT_KEY = 'welcome-to-the-amplience-product-blog' as const;
const EXPECTED_KEYS = ['schema', 'deliveryId', 'deliveryKey'] as const;
const cd1Client = new ContentClient({
account: 'ampproduct',
});
const cd2Client = new ContentClient({
hubName: 'productblog',
});
const cd2FreshClient = new ContentClient({
hubName: 'productblog',
apiKey: 'aEoErhSGEj736mbMl6bd98lzNjk8HweV6jVskqE0',
});
function assertContentItemStructure(contentItem) {
const allKeysPresent = EXPECTED_KEYS.every(
(key) =>
contentItem?._meta[key] && typeof contentItem?._meta[key] === 'string'
);
if (!allKeysPresent) {
throw new Error('Content item does not contain expected _meta properties');
}
}
(async function () {
const cd1ContentById = await cd1Client.getContentItemById(CONTENT_ID);
const cd2ContentById = await cd2Client.getContentItemById(CONTENT_ID);
const cd2ContentByKey = await cd2Client.getContentItemByKey(CONTENT_KEY);
const cd2FreshContentById = await cd2FreshClient.getContentItemById(
CONTENT_ID
);
const cd2FreshContentByKey = await cd2FreshClient.getContentItemByKey(
CONTENT_KEY
);
try {
assertContentItemStructure(cd1ContentById.toJSON());
assertContentItemStructure(cd2ContentById.toJSON());
assertContentItemStructure(cd2ContentByKey.toJSON());
assertContentItemStructure(cd2FreshContentById.toJSON());
assertContentItemStructure(cd2FreshContentByKey.toJSON());
} catch (e) {
console.error(e);
process.exit(1);
}
console.log('\n🎉 All e2e tests passed 🎉\n');
})();