Skip to content

Commit

Permalink
Add tests for invalid embed codes and URLs
Browse files Browse the repository at this point in the history
This also adds a check that the host of the URL includes OpenTable
  • Loading branch information
pablinos committed Feb 14, 2020
1 parent 66455cb commit 6c55fcb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions extensions/blocks/opentable/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { getAttributesFromEmbedCode } from '../utils';

const widgetEmbedCode = "<script type='text/javascript' src='//www.opentable.com/widget/reservation/loader?rid=1&type=standard&theme=standard&iframe=true&domain=com&lang=en-US&newtab=false&ot_source=Restaurant%20website'></script>";

const invalidEmbedCode = "<script type='text/javascript' src='https://www.widgets-r-us.com/widget/widgetygoddness?rid=1&type=standard&theme=standard&iframe=true&domain=com&lang=en-US&newtab=false&ot_source=Restaurant%20website'></script>";

const marketingUrl = "https://www.opentable.com/vongs-thai-kitchen-reservations-chicago?restref=1&lang=en-US&ot_source=Restaurant%20website";

const customUrl1 = "https://www.opentable.com/restref/client/?restref=412810&lang=en-US&ot_source=Restaurant%20website&corrid=e413926b-0352-46d6-a8d8-d1d525932310";
Expand All @@ -17,6 +19,8 @@ const customUrl2 = "https://www.opentable.com/restref/client/?restref=1&lang=es-

const customUrl3 = "https://www.opentable.com/restref/client/?rid=1&corrid=010a3136-569e-42a5-a381-e111887b4cf5";

const invalidUrl = "https://www.widgets-r-us.com/widget/widgetygoddness?rid=1&type=standard&theme=standard&iframe=true&domain=com&lang=en-US&newtab=false&ot_source=Restaurant%20website";

describe( 'getAttributesFromEmbedCode', () => {
test( 'Widget embed code', () => {
expect(
Expand Down Expand Up @@ -75,4 +79,16 @@ describe( 'getAttributesFromEmbedCode', () => {
}
);
} );

test( 'Invaild Embed Code', () => {
expect(
getAttributesFromEmbedCode( invalidEmbedCode )
).toBeUndefined();
} );

test( 'Invaild URL', () => {
expect(
getAttributesFromEmbedCode( invalidUrl )
).toBeUndefined();
} );
} );
2 changes: 1 addition & 1 deletion extensions/blocks/opentable/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getAttributesFromUrl = url => {
src = new URL( 'http:' + url );
}

if ( ! src.search ) {
if ( ! src.host || src.host.indexOf( 'opentable' ) === -1 || ! src.search ) {
return;
}

Expand Down

0 comments on commit 6c55fcb

Please sign in to comment.