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 e109114
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 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
12 changes: 10 additions & 2 deletions exchanges/graphcache/src/offlineExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ const storage = {

describe('storage', () => {
it('should read the metadata and dispatch operations on initialization', () => {
const client = createClient({ url: 'http://0.0.0.0' });
const client = createClient({
url: 'http://0.0.0.0',
exchanges: [],
});

const reexecuteOperation = vi
.spyOn(client, 'reexecuteOperation')
.mockImplementation(() => undefined);
Expand Down Expand Up @@ -100,7 +104,11 @@ describe('offline', () => {
it('should intercept errored mutations', () => {
const onlineSpy = vi.spyOn(navigator, 'onLine', 'get');

const client = createClient({ url: 'http://0.0.0.0' });
const client = createClient({
url: 'http://0.0.0.0',
exchanges: [],
});

const queryOp = client.createRequestOperation('query', {
key: 1,
query: queryOne,
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 e109114

Please sign in to comment.