-
Notifications
You must be signed in to change notification settings - Fork 43
/
C28755.js
81 lines (68 loc) · 2.69 KB
/
C28755.js
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
import { t } from "testcafe";
import createNetworkLogger from "../../helpers/networkLogger";
import { responseStatus } from "../../helpers/assertions/index";
import createFixture from "../../helpers/createFixture";
import {
compose,
orgMainConfigMain,
debugEnabled
} from "../../helpers/constants/configParts";
import getResponseBody from "../../helpers/networkLogger/getResponseBody";
import createResponse from "../../helpers/createResponse";
import { TEST_PAGE as TEST_PAGE_URL } from "../../helpers/constants/url";
import createAlloyProxy from "../../helpers/createAlloyProxy";
const networkLogger = createNetworkLogger();
const config = compose(
orgMainConfigMain,
debugEnabled
);
const PAGE_WIDE_SCOPE = "__view__";
const decisionContent =
'<div id="C28755">Here is an awesome target offer!</div>';
createFixture({
title:
"C28755: The first sendEvent on the page should fetch Personalization VEC offers",
requestHooks: [networkLogger.edgeEndpointLogs],
url: `${TEST_PAGE_URL}?test=C28755`
});
test.meta({
ID: "C28755",
SEVERITY: "P0",
TEST_RUN: "Regression"
});
test("Test C28755: The first sendEvent on the page should fetch Personalization VEC offers", async () => {
const alloy = createAlloyProxy();
await alloy.configure(config);
const result = await alloy.sendEvent();
await responseStatus(networkLogger.edgeEndpointLogs.requests, 200);
await t.expect(networkLogger.edgeEndpointLogs.requests.length).eql(1);
const request = networkLogger.edgeEndpointLogs.requests[0];
const requestBody = JSON.parse(request.request.body);
const personalizationSchemas =
requestBody.events[0].query.personalization.schemas;
await t
.expect(requestBody.events[0].query.personalization.decisionScopes)
.eql([PAGE_WIDE_SCOPE]);
const results = [
"https://ns.adobe.com/personalization/dom-action",
"https://ns.adobe.com/personalization/html-content-item",
"https://ns.adobe.com/personalization/json-content-item",
"https://ns.adobe.com/personalization/redirect-item"
].every(schema => personalizationSchemas.includes(schema));
await t.expect(results).eql(true);
const response = JSON.parse(
getResponseBody(networkLogger.edgeEndpointLogs.requests[0])
);
const personalizationPayload = createResponse({
content: response
}).getPayloadsByType("personalization:decisions");
await t.expect(personalizationPayload[0].scope).eql(PAGE_WIDE_SCOPE);
await t
.expect(personalizationPayload[0].items[0].data.content)
.eql(decisionContent);
await t.expect(result.decisions.length).eql(1);
await t.expect(result.decisions[0].scope).eql(PAGE_WIDE_SCOPE);
await t
.expect(result.decisions[0].items[0].data.content)
.eql(decisionContent);
});