ADD a test for a serverside success & serverside fail checkRef

This commit is contained in:
Norbert de Langen 2020-08-18 14:30:36 +02:00
parent 6380f3943d
commit 0e7dcd63f0
No known key found for this signature in database
GPG Key ID: 976651DA156C2825

View File

@ -538,7 +538,7 @@ describe('Refs API', () => {
`);
});
it('checks refs (cors)', async () => {
it('checks refs (serverside-success)', async () => {
// given
const { api } = initRefs({ provider, store }, { runCheck: false });
@ -600,5 +600,93 @@ describe('Refs API', () => {
}
`);
});
it('checks refs (serverside-fail)', async () => {
// given
const { api } = initRefs({ provider, store }, { runCheck: false });
setupResponses(
{
ok: false,
response: async () => {
throw new Error('Failed to fetch');
},
},
{
ok: false,
response: async () => {
throw new Error('Failed to fetch');
},
},
{
ok: true,
response: async () => {
throw new Error('not ok');
},
},
{
ok: false,
response: async () => {
throw new Error('Failed to fetch');
},
}
);
await api.checkRef({
id: 'fake',
url: 'https://example.com',
title: 'Fake',
type: 'unknown',
});
expect(fetch.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"https://example.com/stories.json",
Object {
"credentials": "include",
"headers": Object {
"Accept": "application/json",
},
},
],
Array [
"https://example.com/stories.json",
Object {
"credentials": "omit",
"headers": Object {
"Accept": "application/json",
},
},
],
]
`);
expect(store.setState.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"refs": Object {
"fake": Object {
"error": Object {
"message": "Error: Loading of ref failed
at fetch (lib/api/src/modules/refs.ts)
URL: https://example.com
We weren't able to load the above URL,
it's possible a CORS error happened.
Please check your dev-tools network tab.",
},
"id": "fake",
"ready": false,
"stories": undefined,
"title": "Fake",
"type": "auto-inject",
"url": "https://example.com",
},
},
}
`);
});
});
});