Skip to content
Snippets Groups Projects
Unverified Commit ac1a651d authored by Nicolò Pretto's avatar Nicolò Pretto Committed by GitHub
Browse files

make `expectGoodSnowplowEvent` output an informative error (#48044)

parent 3069da5d
No related branches found
No related tags found
No related merge requests found
......@@ -28,15 +28,27 @@ export const blockSnowplow = () => {
* @param {number} count - number of matching events you expect to find. defaults to 1
*/
export const expectGoodSnowplowEvent = (eventData, count = 1) => {
let lastReceivedEvent = null;
retrySnowplowRequest(
"micro/good",
({ body }) =>
body.filter(snowplowEvent =>
isDeepMatch(
snowplowEvent?.event?.unstruct_event?.data?.data,
eventData,
),
).length === count,
({ body }) => {
lastReceivedEvent = body?.[0].event?.unstruct_event?.data?.data;
return (
body.filter(snowplowEvent =>
isDeepMatch(
snowplowEvent?.event?.unstruct_event?.data?.data,
eventData,
),
).length === count
);
},
() =>
`Expected ${count} good Snowplow events with data: ${JSON.stringify(
eventData,
null,
2,
)}\n Last event found was ${JSON.stringify(lastReceivedEvent, null, 2)}`,
).should("be.ok");
};
......@@ -104,15 +116,29 @@ const sendSnowplowRequest = url => {
});
};
const retrySnowplowRequest = (url, condition, timeout = SNOWPLOW_TIMEOUT) => {
const retrySnowplowRequest = (
url,
condition,
messageOrMessageFn = null,
timeout = SNOWPLOW_TIMEOUT,
) => {
return sendSnowplowRequest(url).then(response => {
if (condition(response)) {
return cy.wrap(response);
} else if (timeout > 0) {
cy.wait(SNOWPLOW_INTERVAL);
return retrySnowplowRequest(url, condition, timeout - SNOWPLOW_INTERVAL);
return retrySnowplowRequest(
url,
condition,
messageOrMessageFn,
timeout - SNOWPLOW_INTERVAL,
);
} else {
throw new Error("Snowplow retry timeout");
const message =
typeof messageOrMessageFn === "function"
? messageOrMessageFn()
: messageOrMessageFn;
throw new Error("Snowplow retry timeout " + message);
}
});
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment