Skip to content

Commit

Permalink
fix(build): Fix buildEvents tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTolmay committed May 28, 2022
1 parent ef7734b commit 0dcb927
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
9 changes: 6 additions & 3 deletions packages/build/src/build/buildPages/buildBlock/buildEvents.js
Expand Up @@ -51,7 +51,10 @@ function checkAction(action, { blockId, checkDuplicateActionId, eventId, pageId,
function buildEvents(block, pageContext) {
if (block.events) {
Object.keys(block.events).map((key) => {
if (!type.isArray(block.events[key]) && !type.isObject(block.events[key])) {
if (
(!type.isArray(block.events[key]) && !type.isObject(block.events[key])) ||
(type.isObject(block.events[key]) && type.isNone(block.events[key].try))
) {
throw new Error(
`Actions must be an array at "${block.blockId}" in event "${key}" on page "${
pageContext.pageId
Expand All @@ -66,14 +69,14 @@ function buildEvents(block, pageContext) {
}
if (!type.isArray(block.events[key].try)) {
throw new Error(
`Try Actions must be an array at "${block.blockId}" in event "${key}" on page "${
`Try actions must be an array at "${block.blockId}" in event "${key}.try" on page "${
pageContext.pageId
}". Received ${JSON.stringify(block.events[key].try)}`
);
}
if (!type.isArray(block.events[key].catch)) {
throw new Error(
`Catch actions must be an array at "${block.blockId}" in event "${key}" on page "${
`Catch actions must be an array at "${block.blockId}" in event "${key}.catch" on page "${
pageContext.pageId
}". Received ${JSON.stringify(block.events[key].catch)}`
);
Expand Down
22 changes: 11 additions & 11 deletions packages/build/src/build/buildPages/buildBlock/buildEvents.test.js
Expand Up @@ -146,14 +146,14 @@ test('block events actions as try array and catch not defined.', () => {
},
],
};
const res = buildPages({ components, context });
expect(get(res, 'pages.0.areas.content.blocks.0.events.onClick.try')).toEqual([
{
id: 'action_1',
type: 'Reset',
},
]);
expect(get(res, 'pages.0.areas.content.blocks.0.events.onClick.catch')).toEqual([]);
expect(() =>
buildPages({
components,
context,
})
).toThrow(
'Catch actions must be an array at "block_1" in event "onClick.catch" on page "page_1". Received undefined'
);
});

test('block events actions try not an array', () => {
Expand Down Expand Up @@ -186,7 +186,7 @@ test('block events actions try not an array', () => {
context,
})
).toThrow(
'Events must be an array of actions at "block_1" in event "onClick" on page "page_1". Received {"id":"action_1","type":"Reset"}'
'Try actions must be an array at "block_1" in event "onClick.try" on page "page_1". Received {"id":"action_1","type":"Reset"}'
);
});

Expand All @@ -210,7 +210,7 @@ test('block events actions not an array', () => {
],
};
expect(() => buildPages({ components, context })).toThrow(
'Events must be an array of actions at "block_1" in event "onClick" on page "page_1". Received undefined'
'Actions must be an array at "block_1" in event "onClick" on page "page_1". Received undefined'
);
});

Expand Down Expand Up @@ -240,7 +240,7 @@ test('block events actions catch not an array', () => {
],
};
expect(() => buildPages({ components, context })).toThrow(
'Catch events must be an array of actions at "block_1" in event "onClick" on page "page_1". Received {"id":"action_1","type":"Reset"}'
'Catch actions must be an array at "block_1" in event "onClick.catch" on page "page_1". Received {"id":"action_1","type":"Reset"}'
);
});

Expand Down

0 comments on commit 0dcb927

Please sign in to comment.