Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset embed mocks on every request, stop request to instagram #15046

Merged
merged 2 commits into from
Apr 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/e2e-tests/specs/embedding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
clickBlockAppender,
createNewPost,
createEmbeddingMatcher,
createURLMatcher,
setUpResponseMocking,
createJSONResponse,
getEditedPostContent,
Expand Down Expand Up @@ -124,6 +125,12 @@ const MOCK_RESPONSES = [
match: createEmbeddingMatcher( 'https://twitter.com/wooyaygutenberg123454312' ),
onRequestMatch: createJSONResponse( MOCK_CANT_EMBED_RESPONSE ),
},
// Respond to the instagram URL with a non-image response, doesn't matter what it is,
// just make sure the image errors.
{
match: createURLMatcher( 'https://www.instagram.com/p/Bvl97o2AK6x/' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the other matcher?

match: createEmbeddingMatcher( 'https://www.instagram.com/p/Bvl97o2AK6x/' ),
onRequestMatch: createJSONResponse( MOCK_EMBED_IMAGE_SUCCESS_RESPONSE ),

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't seem to be used at the moment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, one is to match the embed preview request for the URL and one is to match the URL itself. The image block creates a new image, and sets the URL as the source. If the image errors, it replaces itself with an appropriate embed block if there is one. So we need to mock the instagram URL, and the embed proxy call that generates the preview.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, it makes sense now :)

onRequestMatch: createJSONResponse( MOCK_CANT_EMBED_RESPONSE ),
},
];

const addAllEmbeds = async () => {
Expand Down Expand Up @@ -178,8 +185,10 @@ const addAllEmbeds = async () => {
};

describe( 'Embedding content', () => {
beforeAll( async () => await setUpResponseMocking( MOCK_RESPONSES ) );
beforeEach( createNewPost );
beforeEach( async () => {
await setUpResponseMocking( MOCK_RESPONSES );
await createNewPost();
} );

it( 'should render embeds in the correct state', async () => {
await addAllEmbeds();
Expand Down