Skip to content

Commit

Permalink
Update persisted/multipart/execute tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Mar 14, 2023
1 parent fb671e3 commit 060153a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions exchanges/execute/src/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ describe('on operation', () => {

fetchMock.mockResolvedValue({
status: 200,
headers: { get: () => 'application/json' },
text: vi
.fn()
.mockResolvedValue(JSON.stringify({ data: mockHttpResponseData })),
Expand Down
3 changes: 3 additions & 0 deletions exchanges/multipart-fetch/src/multipartFetchExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('on success', () => {
beforeEach(() => {
fetch.mockResolvedValue({
status: 200,
headers: { get: () => 'application/json' },
text: vi.fn().mockResolvedValue(response),
});
});
Expand Down Expand Up @@ -128,6 +129,7 @@ describe('on error', () => {
beforeEach(() => {
fetch.mockResolvedValue({
status: 400,
headers: { get: () => 'application/json' },
text: vi.fn().mockResolvedValue('{}'),
});
});
Expand Down Expand Up @@ -163,6 +165,7 @@ describe('on error', () => {
it('ignores the error when a result is available', async () => {
fetch.mockResolvedValue({
status: 400,
headers: { get: () => 'application/json' },
text: vi.fn().mockResolvedValue(response),
});

Expand Down
16 changes: 16 additions & 0 deletions exchanges/persisted-fetch/src/persistedFetchExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ it('accepts successful persisted query responses', async () => {
});

fetch.mockResolvedValueOnce({
status: 200,
headers: { get: () => 'application/json' },
text: () => Promise.resolve(expected),
});

Expand Down Expand Up @@ -63,9 +65,13 @@ it('supports cache-miss persisted query errors', async () => {

fetch
.mockResolvedValueOnce({
status: 200,
headers: { get: () => 'application/json' },
text: () => Promise.resolve(expectedMiss),
})
.mockResolvedValueOnce({
status: 200,
headers: { get: () => 'application/json' },
text: () => Promise.resolve(expectedRetry),
});

Expand Down Expand Up @@ -94,9 +100,13 @@ it('supports GET exclusively for persisted queries', async () => {

fetch
.mockResolvedValueOnce({
status: 200,
headers: { get: () => 'application/json' },
text: () => Promise.resolve(expectedMiss),
})
.mockResolvedValueOnce({
status: 200,
headers: { get: () => 'application/json' },
text: () => Promise.resolve(expectedRetry),
});

Expand Down Expand Up @@ -127,12 +137,18 @@ it('supports unsupported persisted query errors', async () => {

fetch
.mockResolvedValueOnce({
status: 200,
headers: { get: () => 'application/json' },
text: () => Promise.resolve(expectedMiss),
})
.mockResolvedValueOnce({
status: 200,
headers: { get: () => 'application/json' },
text: () => Promise.resolve(expectedRetry),
})
.mockResolvedValueOnce({
status: 200,
headers: { get: () => 'application/json' },
text: () => Promise.resolve(expectedRetry),
});

Expand Down
10 changes: 7 additions & 3 deletions packages/svelte-urql/src/mutationStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import { vi, expect, it, describe } from 'vitest';
import { mutationStore } from './mutationStore';

describe('mutationStore', () => {
const client = createClient({ url: 'https://example.com' });
const client = createClient({
url: 'noop',
exchanges: [],
});

const variables = {};
const context = {};

const query =
'mutation ($input: Example!) { doExample(input: $input) { id } }';
const store = mutationStore({
Expand All @@ -26,14 +31,13 @@ describe('mutationStore', () => {

it('fills the store with correct values', () => {
expect(get(store).operation.kind).toBe('mutation');
expect(get(store).operation.context.url).toBe('https://example.com');
expect(get(store).operation.context.url).toBe('noop');
expect(get(store).operation.variables).toBe(variables);

expect(print(get(store).operation.query)).toMatchInlineSnapshot(`
"mutation ($input: Example!) {
doExample(input: $input) {
id
__typename
}
}"
`);
Expand Down
6 changes: 5 additions & 1 deletion packages/svelte-urql/src/queryStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { get } from 'svelte/store';
import { queryStore } from './queryStore';

describe('queryStore', () => {
const client = createClient({ url: 'https://example.com' });
const client = createClient({
url: 'https://example.com',
exchanges: [],
});

const variables = {};
const context = {};
const query = '{ test }';
Expand Down
6 changes: 5 additions & 1 deletion packages/svelte-urql/src/subscriptionStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { vi, expect, it, describe } from 'vitest';
import { subscriptionStore } from './subscriptionStore';

describe('subscriptionStore', () => {
const client = createClient({ url: 'https://example.com' });
const client = createClient({
url: 'https://example.com',
exchanges: [],
});

const variables = {};
const context = {};
const query = `subscription ($input: ExampleInput) { exampleSubscribe(input: $input) { data } }`;
Expand Down

0 comments on commit 060153a

Please sign in to comment.