diff options
Diffstat (limited to 'src/stores')
22 files changed, 0 insertions, 1760 deletions
diff --git a/src/stores/.actions.js.icloud b/src/stores/.actions.js.icloud Binary files differnew file mode 100644 index 0000000..d92becf --- /dev/null +++ b/src/stores/.actions.js.icloud diff --git a/src/stores/.actions.test.js.icloud b/src/stores/.actions.test.js.icloud Binary files differnew file mode 100644 index 0000000..a48942f --- /dev/null +++ b/src/stores/.actions.test.js.icloud diff --git a/src/stores/.apollo.js.icloud b/src/stores/.apollo.js.icloud Binary files differnew file mode 100644 index 0000000..7a785f5 --- /dev/null +++ b/src/stores/.apollo.js.icloud diff --git a/src/stores/.forums.js.icloud b/src/stores/.forums.js.icloud Binary files differnew file mode 100644 index 0000000..a89466f --- /dev/null +++ b/src/stores/.forums.js.icloud diff --git a/src/stores/.forums.test.js.icloud b/src/stores/.forums.test.js.icloud Binary files differnew file mode 100644 index 0000000..a77ae7c --- /dev/null +++ b/src/stores/.forums.test.js.icloud diff --git a/src/stores/.posts.js.icloud b/src/stores/.posts.js.icloud Binary files differnew file mode 100644 index 0000000..dc9200d --- /dev/null +++ b/src/stores/.posts.js.icloud diff --git a/src/stores/.posts.test.js.icloud b/src/stores/.posts.test.js.icloud Binary files differnew file mode 100644 index 0000000..9136b81 --- /dev/null +++ b/src/stores/.posts.test.js.icloud diff --git a/src/stores/.tags.js.icloud b/src/stores/.tags.js.icloud Binary files differnew file mode 100644 index 0000000..0fbf818 --- /dev/null +++ b/src/stores/.tags.js.icloud diff --git a/src/stores/.tags.test.js.icloud b/src/stores/.tags.test.js.icloud Binary files differnew file mode 100644 index 0000000..d67a70f --- /dev/null +++ b/src/stores/.tags.test.js.icloud diff --git a/src/stores/.topics.js.icloud b/src/stores/.topics.js.icloud Binary files differnew file mode 100644 index 0000000..7c07a38 --- /dev/null +++ b/src/stores/.topics.js.icloud diff --git a/src/stores/.topics.test.js.icloud b/src/stores/.topics.test.js.icloud Binary files differnew file mode 100644 index 0000000..425aca9 --- /dev/null +++ b/src/stores/.topics.test.js.icloud diff --git a/src/stores/actions.js b/src/stores/actions.js deleted file mode 100644 index f7fbc28..0000000 --- a/src/stores/actions.js +++ /dev/null @@ -1,32 +0,0 @@ -import { derived, writable } from 'svelte/store'; - -/* - * This is a store to set the actions in the top header. - */ - -const actions = writable({}); - -export const enableTopicActions = (id) => { - - actions.update((actionsValue) => { - - actionsValue.topic = { - id - }; - return actionsValue; - }); -}; - -export const disableTopicActions = () => { - - actions.update((actionsValue) => { - - delete actionsValue.topic; - return actionsValue; - }); -}; - -export const topicActions = derived( - actions, - ($actions) => $actions.topic -); diff --git a/src/stores/actions.test.js b/src/stores/actions.test.js deleted file mode 100644 index c650536..0000000 --- a/src/stores/actions.test.js +++ /dev/null @@ -1,32 +0,0 @@ -import { enableTopicActions, disableTopicActions, topicActions } from './actions'; - -describe('Topic actions and state', () => { - - test('There should be no topic actions by default', () => { - - topicActions.subscribe((actions) => { - - expect(actions).toBe(undefined); - })(); - }); - - test('enableTopicActions should set the topic id', () => { - - enableTopicActions('free_hat'); - topicActions.subscribe((actions) => { - - expect(actions).toEqual({ - id: 'free_hat' - }); - })(); - }); - - test('disableTopicActions should unset the topic id', () => { - - disableTopicActions(); - topicActions.subscribe((actions) => { - - expect(actions).toEqual(undefined); - })(); - }); -}); diff --git a/src/stores/apollo.js b/src/stores/apollo.js deleted file mode 100644 index f84a183..0000000 --- a/src/stores/apollo.js +++ /dev/null @@ -1,46 +0,0 @@ -import { ApolloError } from '@apollo/client/core'; -import { readable } from 'svelte/store'; -import { client } from '$/config/apollo'; - -/* - * This is a generic store for use with apollo - */ - -export const store = function store({ key, query, initialValue = null, variables = {} }) { - - return readable( - { - loading: true, - data: initialValue, - error: undefined - }, - (set) => { - - const handleError = function (error) { - - return set({ - loading: false, - data: initialValue, - error - }); - }; - - client.watchQuery({ query, variables }).subscribe( - (result) => { - - if (result.errors) { - const error = new ApolloError({ graphQLErrors: result.errors }); - return handleError(error); - } - - set({ - loading: false, - data: result.data[key], - error: undefined - }); - }, - (error) => handleError(error) - ); - } - ); -}; diff --git a/src/stores/forums.js b/src/stores/forums.js deleted file mode 100644 index 2c03a05..0000000 --- a/src/stores/forums.js +++ /dev/null @@ -1,5 +0,0 @@ -import { store } from './apollo'; -import { GET_FORUM, GET_FORUMS } from '$/data/queries'; - -export const getForum = (id) => store({ key: 'forum', query: GET_FORUM, variables: { id } }); -export const getForums = () => store({ key: 'forums', query: GET_FORUMS, initialValue: [] }); diff --git a/src/stores/forums.test.js b/src/stores/forums.test.js deleted file mode 100644 index 732964f..0000000 --- a/src/stores/forums.test.js +++ /dev/null @@ -1,570 +0,0 @@ -import { GraphQLInteraction, Pact, Matchers } from '@pact-foundation/pact'; -import { resolve } from 'path'; - -import { resolveAfter } from '$/utils/resolve_after'; - -const { eachLike, like } = Matchers; - -jest.mock('$/config/config.js'); - -import { getForum, getForums } from './forums'; - -const internals = { - provider: null -}; - -describe('Forums store pact', () => { - - beforeAll(async () => { - - internals.provider = new Pact({ - port: 1234, - dir: resolve(process.cwd(), 'pacts'), - consumer: 'ForumClient', - provider: 'ForumServer', - pactfileWriteMode: 'update' - }); - - await internals.provider.setup(); - }); - - afterEach(() => internals.provider.verify()); - afterAll(() => internals.provider.finalize()); - - describe('When there\'s data', () => { - - describe('GetForums', () => { - - beforeAll(async () => { - - const forumQuery = new GraphQLInteraction() - .given('there\'s data') - .uponReceiving('a request to list the forums') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetForums') - .withQuery( - `query GetForums { - forums { - id - glyph - label - position - __typename - } - }` - ) - .withVariables({}) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - data: { - forums: eachLike({ - id: like('butter'), - glyph: like('⌘'), - label: like('test_forums.butter'), - position: like(1) - }) - } - } - }); - return await internals.provider.addInteraction(forumQuery); - }); - - test('it returns the forums', async () => { - - const forums = getForums(); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - forums.subscribe((forumsValue) => { - - response = forumsValue; - counter(); - }); - expect(response.data).toBeInstanceOf(Array); - expect(response.data.length).toBe(0); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toEqual(expect.arrayContaining([{ - id: 'butter', - glyph: '⌘', - label: 'test_forums.butter', - position: 1 - }])); - expect(response.loading).toBe(false); - expect(response.error).toBe(undefined); - }); - }); - - describe('GetForum', () => { - - beforeAll(async () => { - - const forumQuery = new GraphQLInteraction() - .given('there\'s data') - .uponReceiving('a request to get a single forum') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetForum') - .withQuery( - `query GetForum($id: ID!) { - forum(id: $id) { - id - glyph - label - position - topics { - id - title - updated_at - ttl - __typename - } - __typename - } - }` - ) - .withVariables({ - id: 'freezer' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - data: { - forum: like({ - id: 'freezer', - glyph: like('✭'), - label: like('test_forums.freezer'), - position: like(3), - topics: eachLike({ - id: like('629de02c-151a-4db7-bb86-43b2add8a15a'), - title: like('Very pacty topic'), - updated_at: like(1619954611616), - ttl: like(3601) - }) - }) - } - } - }); - return await internals.provider.addInteraction(forumQuery); - }); - - test('it returns the forum', async () => { - - const forum = getForum('freezer'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - forum.subscribe((forumsValue) => { - - response = forumsValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data.id).toBe('freezer'); - expect(response.data.glyph).toBe('✭'); - expect(response.data.label).toBe('test_forums.freezer'); - expect(response.data.position).toBe(3); - expect(response.data.topics).toEqual(expect.arrayContaining([{ - id: '629de02c-151a-4db7-bb86-43b2add8a15a', - title: 'Very pacty topic', - updated_at: 1619954611616, - ttl: 3601 - }])); - expect(response.loading).toBe(false); - expect(response.error).toBe(undefined); - }); - }); - }); - - describe('When there\'s no data', () => { - - describe('GetForums', () => { - - beforeAll(async () => { - - const forumQuery = new GraphQLInteraction() - .given('there\'s no data') - .uponReceiving('a request to list the forums') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetForums') - .withQuery( - `query GetForums { - forums { - id - glyph - label - position - __typename - } - }` - ) - .withVariables({}) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - data: { - forums: [] - } - } - }); - return await internals.provider.addInteraction(forumQuery); - }); - - test('it returns the forums', async () => { - - const forums = getForums(); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - forums.subscribe((forumsValue) => { - - response = forumsValue; - counter(); - }); - expect(response.data).toBeInstanceOf(Array); - expect(response.data.length).toBe(0); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBeInstanceOf(Array); - expect(response.data.length).toBe(0); - expect(response.loading).toBe(false); - expect(response.error).toBe(undefined); - }); - }); - - describe('GetForum', () => { - - beforeAll(async () => { - - const forumQuery = new GraphQLInteraction() - .given('there\'s no data') - .uponReceiving('a request to get a single forum') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetForum') - .withQuery( - `query GetForum($id: ID!) { - forum(id: $id) { - id - glyph - label - position - topics { - id - title - updated_at - ttl - __typename - } - __typename - } - }` - ) - .withVariables({ - id: 'freezer' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - data: { - forum: null - } - } - }); - return await internals.provider.addInteraction(forumQuery); - }); - - test('it returns the forum', async () => { - - const forum = getForum('freezer'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - forum.subscribe((forumsValue) => { - - response = forumsValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error).toBe(undefined); - }); - }); - }); - - describe('When there\'s a server error', () => { - - describe('GetForums', () => { - - beforeAll(async () => { - - const forumQuery = new GraphQLInteraction() - .given('there\'s a server error') - .uponReceiving('a request to list the forums') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetForums') - .withQuery( - `query GetForums { - forums { - id - glyph - label - position - __typename - } - }` - ) - .withVariables({}) - .willRespondWith({ - status: 500 - }); - return await internals.provider.addInteraction(forumQuery); - }); - - test('it returns the error', async () => { - - const forums = getForums(); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - forums.subscribe((forumsValue) => { - - response = forumsValue; - counter(); - }); - expect(response.data).toBeInstanceOf(Array); - expect(response.data.length).toBe(0); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBeInstanceOf(Array); - expect(response.data.length).toBe(0); - expect(response.loading).toBe(false); - expect(response.error).toBeInstanceOf(Error); - }); - }); - - describe('GetForum', () => { - - beforeAll(async () => { - - const forumQuery = new GraphQLInteraction() - .given('there\'s a server error') - .uponReceiving('a request to get a single forum') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetForum') - .withQuery( - `query GetForum($id: ID!) { - forum(id: $id) { - id - glyph - label - position - topics { - id - title - updated_at - ttl - __typename - } - __typename - } - }` - ) - .withVariables({ - id: 'freezer' - }) - .willRespondWith({ - status: 500 - }); - return await internals.provider.addInteraction(forumQuery); - }); - - test('it returns the error', async () => { - - const forum = getForum('freezer'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - forum.subscribe((forumsValue) => { - - response = forumsValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error).toBeInstanceOf(Error); - }); - }); - }); - - describe('When there\'s an error in the response', () => { - - describe('GetForums', () => { - - beforeAll(async () => { - - const forumQuery = new GraphQLInteraction() - .given('there\'s an error in the response') - .uponReceiving('a request to list the forums') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetForums') - .withQuery( - `query GetForums { - forums { - id - glyph - label - position - __typename - } - }` - ) - .withVariables({}) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - errors: eachLike({ - message: like('An error occurred when fetching forums') - }) - } - }); - return await internals.provider.addInteraction(forumQuery); - }); - - test('it returns the error', async () => { - - const forums = getForums(); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - forums.subscribe((forumsValue) => { - - response = forumsValue; - counter(); - }); - expect(response.data).toBeInstanceOf(Array); - expect(response.data.length).toBe(0); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBeInstanceOf(Array); - expect(response.data.length).toBe(0); - expect(response.loading).toBe(false); - expect(response.error.graphQLErrors).toEqual(expect.arrayContaining([{ - message: 'An error occurred when fetching forums' - }])); - }); - }); - - describe('GetForum', () => { - - beforeAll(async () => { - - const forumQuery = new GraphQLInteraction() - .given('there\'s an error in the response') - .uponReceiving('a request to get a single forum') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetForum') - .withQuery( - `query GetForum($id: ID!) { - forum(id: $id) { - id - glyph - label - position - topics { - id - title - updated_at - ttl - __typename - } - __typename - } - }` - ) - .withVariables({ - id: 'freezer' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - errors: eachLike({ - message: like('An error occurred when fetching the forum') - }) - } - }); - return await internals.provider.addInteraction(forumQuery); - }); - - test('it returns the error', async () => { - - const forum = getForum('freezer'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - forum.subscribe((forumsValue) => { - - response = forumsValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error.graphQLErrors).toEqual(expect.arrayContaining([{ - message: 'An error occurred when fetching the forum' - }])); - }); - }); - }); -}); diff --git a/src/stores/posts.js b/src/stores/posts.js deleted file mode 100644 index 0cbf1d5..0000000 --- a/src/stores/posts.js +++ /dev/null @@ -1,4 +0,0 @@ -import { store } from './apollo'; -import { GET_POST } from '$/data/queries'; - -export const getPost = (id) => store({ key: 'post', query: GET_POST, variables: { id } }); diff --git a/src/stores/posts.test.js b/src/stores/posts.test.js deleted file mode 100644 index ab17286..0000000 --- a/src/stores/posts.test.js +++ /dev/null @@ -1,339 +0,0 @@ -import { GraphQLInteraction, Pact, Matchers } from '@pact-foundation/pact'; -import { resolve } from 'path'; - -import { resolveAfter } from '$/utils/resolve_after'; - -const { eachLike, like } = Matchers; - -jest.mock('$/config/config.js'); - -import { getPost } from './posts'; - -const internals = { - provider: null -}; - -describe('Posts store pact', () => { - - beforeAll(async () => { - - internals.provider = new Pact({ - port: 1234, - dir: resolve(process.cwd(), 'pacts'), - consumer: 'ForumClient', - provider: 'ForumServer', - pactfileWriteMode: 'update' - }); - - await internals.provider.setup(); - }); - - afterEach(() => internals.provider.verify()); - afterAll(() => internals.provider.finalize()); - - describe('When there\'s data', () => { - - describe('GetPost', () => { - - beforeAll(async () => { - - const postQuery = new GraphQLInteraction() - .given('there\'s data') - .uponReceiving('a request to get a single post') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetPost') - .withQuery( - `query GetPost($id: ID!) { - post(id: $id) { - id - text - created_at - author { - id - handle - __typename - } - topic { - id - title - __typename - } - __typename - } - }` - ) - .withVariables({ - id: '8f75eba5-6989-4dd3-b466-e464546ce374' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - data: { - post: like({ - id: like('8f75eba5-6989-4dd3-b466-e464546ce374'), - text: like('This is a very pacty post'), - created_at: like(1619976194937), - author: like({ - id: like('a805b3de-cac4-451c-a1e6-f078869c9db9'), - handle: like('pacts_person') - }), - topic: like({ - id: like('5c283ce1-0470-4b98-86f5-1fec9a22c9ac'), - title: like('The parent pacts topic') - }) - }) - } - } - }); - return await internals.provider.addInteraction(postQuery); - }); - - test('it returns the post', async () => { - - const post = getPost('8f75eba5-6989-4dd3-b466-e464546ce374'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - post.subscribe((postValue) => { - - response = postValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toEqual({ - id: '8f75eba5-6989-4dd3-b466-e464546ce374', - text: 'This is a very pacty post', - created_at: 1619976194937, - author: { - id: 'a805b3de-cac4-451c-a1e6-f078869c9db9', - handle: 'pacts_person' - }, - topic: { - id: '5c283ce1-0470-4b98-86f5-1fec9a22c9ac', - title: 'The parent pacts topic' - } - }); - expect(response.loading).toBe(false); - expect(response.error).toBe(undefined); - }); - }); - }); - - describe('When there\'s no data', () => { - - describe('GetPost', () => { - - beforeAll(async () => { - - const postQuery = new GraphQLInteraction() - .given('there\'s no data') - .uponReceiving('a request to get a single post') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetPost') - .withQuery( - `query GetPost($id: ID!) { - post(id: $id) { - id - text - created_at - author { - id - handle - __typename - } - topic { - id - title - __typename - } - __typename - } - }` - ) - .withVariables({ - id: '8f75eba5-6989-4dd3-b466-e464546ce374' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - data: { - post: null - } - } - }); - return await internals.provider.addInteraction(postQuery); - }); - - test('it returns the post', async () => { - - const post = getPost('8f75eba5-6989-4dd3-b466-e464546ce374'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - post.subscribe((postValue) => { - - response = postValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error).toBe(undefined); - }); - }); - }); - - describe('When there\'s a server error', () => { - - describe('GetPost', () => { - - beforeAll(async () => { - - const postQuery = new GraphQLInteraction() - .given('there\'s a server error') - .uponReceiving('a request to get a single post') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetPost') - .withQuery( - `query GetPost($id: ID!) { - post(id: $id) { - id - text - created_at - author { - id - handle - __typename - } - topic { - id - title - __typename - } - __typename - } - }` - ) - .withVariables({ - id: '8f75eba5-6989-4dd3-b466-e464546ce374' - }) - .willRespondWith({ - status: 500 - }); - return await internals.provider.addInteraction(postQuery); - }); - - test('it returns the error', async () => { - - const post = getPost('8f75eba5-6989-4dd3-b466-e464546ce374'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - post.subscribe((postValue) => { - - response = postValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error).toBeInstanceOf(Error); - }); - }); - }); - - describe('When there\'s an error in the response', () => { - - describe('GetPost', () => { - - beforeAll(async () => { - - const postQuery = new GraphQLInteraction() - .given('there\'s an error in the response') - .uponReceiving('a request to get a single post') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetPost') - .withQuery( - `query GetPost($id: ID!) { - post(id: $id) { - id - text - created_at - author { - id - handle - __typename - } - topic { - id - title - __typename - } - __typename - } - }` - ) - .withVariables({ - id: '8f75eba5-6989-4dd3-b466-e464546ce374' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - errors: eachLike({ - message: like('An error occurred when fetching the post') - }) - } - }); - return await internals.provider.addInteraction(postQuery); - }); - - test('it returns the error', async () => { - - const post = getPost('8f75eba5-6989-4dd3-b466-e464546ce374'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - post.subscribe((postValue) => { - - response = postValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error.graphQLErrors).toEqual(expect.arrayContaining([{ - message: 'An error occurred when fetching the post' - }])); - }); - }); - }); -}); diff --git a/src/stores/tags.js b/src/stores/tags.js deleted file mode 100644 index d74b719..0000000 --- a/src/stores/tags.js +++ /dev/null @@ -1,4 +0,0 @@ -import { store } from './apollo'; -import { GET_TAG } from '$/data/queries'; - -export const getTag = (id) => store({ key: 'tag', query: GET_TAG, variables: { id } }); diff --git a/src/stores/tags.test.js b/src/stores/tags.test.js deleted file mode 100644 index bf4fa56..0000000 --- a/src/stores/tags.test.js +++ /dev/null @@ -1,311 +0,0 @@ -import { GraphQLInteraction, Pact, Matchers } from '@pact-foundation/pact'; -import { resolve } from 'path'; - -import { resolveAfter } from '$/utils/resolve_after'; - -const { eachLike, like } = Matchers; - -jest.mock('$/config/config.js'); - -import { getTag } from './tags'; - -const internals = { - provider: null -}; - -describe('Tags store pact', () => { - - beforeAll(async () => { - - internals.provider = new Pact({ - port: 1234, - dir: resolve(process.cwd(), 'pacts'), - consumer: 'ForumClient', - provider: 'ForumServer', - pactfileWriteMode: 'update' - }); - - await internals.provider.setup(); - }); - - afterEach(() => internals.provider.verify()); - afterAll(() => internals.provider.finalize()); - - describe('When there\'s data', () => { - - describe('GetTag', () => { - - beforeAll(async () => { - - const tagQuery = new GraphQLInteraction() - .given('there\'s data') - .uponReceiving('a request to get a single tag') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetTag') - .withQuery( - `query GetTag($id: ID!) { - tag(id: $id) { - id - topics { - id - title - updated_at - ttl - __typename - } - __typename - } - }` - ) - .withVariables({ - id: 'pineapple' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - data: { - tag: { - id: like('pineapple'), - topics: eachLike({ - id: like('cd038ae7-e8b4-4e38-9543-3d697e69ac34'), - title: like('This topic is about pineapples'), - updated_at: like(1619978944077), - ttl: like(3555) - }) - } - } - } - }); - return await internals.provider.addInteraction(tagQuery); - }); - - test('it returns the tag', async () => { - - const tag = getTag('pineapple'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - tag.subscribe((tagValue) => { - - response = tagValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toEqual({ - id: 'pineapple', - topics: [{ - id: 'cd038ae7-e8b4-4e38-9543-3d697e69ac34', - title: 'This topic is about pineapples', - updated_at: 1619978944077, - ttl: 3555 - }] - }); - expect(response.loading).toBe(false); - expect(response.error).toBe(undefined); - }); - }); - }); - - describe('When there\'s no data', () => { - - describe('GetTag', () => { - - beforeAll(async () => { - - const tagQuery = new GraphQLInteraction() - .given('there\'s no data') - .uponReceiving('a request to get a single tag') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetTag') - .withQuery( - `query GetTag($id: ID!) { - tag(id: $id) { - id - topics { - id - title - updated_at - ttl - __typename - } - __typename - } - }` - ) - .withVariables({ - id: 'pineapple' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - data: { - tag: null - } - } - }); - return await internals.provider.addInteraction(tagQuery); - }); - - test('it returns the tag', async () => { - - const tag = getTag('pineapple'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - tag.subscribe((tagValue) => { - - response = tagValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error).toBe(undefined); - }); - }); - }); - - describe('When there\'s a server error', () => { - - describe('GetTag', () => { - - beforeAll(async () => { - - const tagQuery = new GraphQLInteraction() - .given('there\'s a server error') - .uponReceiving('a request to get a single tag') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetTag') - .withQuery( - `query GetTag($id: ID!) { - tag(id: $id) { - id - topics { - id - title - updated_at - ttl - __typename - } - __typename - } - }` - ) - .withVariables({ - id: 'pineapple' - }) - .willRespondWith({ - status: 500 - }); - return await internals.provider.addInteraction(tagQuery); - }); - - test('it returns the error', async () => { - - const tag = getTag('pineapple'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - tag.subscribe((tagValue) => { - - response = tagValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error).toBeInstanceOf(Error); - }); - }); - }); - - describe('When there\'s an error in the response', () => { - - describe('GetTag', () => { - - beforeAll(async () => { - - const tagQuery = new GraphQLInteraction() - .given('there\'s an error in the response') - .uponReceiving('a request to get a single tag') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetTag') - .withQuery( - `query GetTag($id: ID!) { - tag(id: $id) { - id - topics { - id - title - updated_at - ttl - __typename - } - __typename - } - }` - ) - .withVariables({ - id: 'pineapple' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - errors: eachLike({ - message: like('An error occurred when fetching the tag') - }) - } - }); - return await internals.provider.addInteraction(tagQuery); - }); - - test('it returns the error', async () => { - - const tag = getTag('pineapple'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - tag.subscribe((tagValue) => { - - response = tagValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error.graphQLErrors).toEqual(expect.arrayContaining([{ - message: 'An error occurred when fetching the tag' - }])); - }); - }); - }); -}); diff --git a/src/stores/topics.js b/src/stores/topics.js deleted file mode 100644 index c90f1a3..0000000 --- a/src/stores/topics.js +++ /dev/null @@ -1,4 +0,0 @@ -import { store } from './apollo'; -import { GET_TOPIC } from '$/data/queries'; - -export const getTopic = (id) => store({ key: 'topic', query: GET_TOPIC, variables: { id } }); diff --git a/src/stores/topics.test.js b/src/stores/topics.test.js deleted file mode 100644 index 7c3285b..0000000 --- a/src/stores/topics.test.js +++ /dev/null @@ -1,413 +0,0 @@ -import { GraphQLInteraction, Pact, Matchers } from '@pact-foundation/pact'; -import { resolve } from 'path'; - -import { resolveAfter } from '$/utils/resolve_after'; - -const { eachLike, like } = Matchers; - -jest.mock('$/config/config.js'); - -import { getTopic } from './topics'; - -const internals = { - provider: null -}; - -describe('Topics store pact', () => { - - beforeAll(async () => { - - internals.provider = new Pact({ - port: 1234, - dir: resolve(process.cwd(), 'pacts'), - consumer: 'ForumClient', - provider: 'ForumServer', - pactfileWriteMode: 'update' - }); - - await internals.provider.setup(); - }); - - afterEach(() => internals.provider.verify()); - afterAll(() => internals.provider.finalize()); - - describe('When there\'s data', () => { - - describe('GetTopic', () => { - - beforeAll(async () => { - - const topicQuery = new GraphQLInteraction() - .given('there\'s data') - .uponReceiving('a request to get a single topic') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetTopic') - .withQuery( - `query GetTopic($id: ID!) { - topic(id: $id) { - id - title - updated_at - ttl - forum { - id - glyph - label - __typename - } - tags { - id - weight - __typename - } - posts { - id - text - created_at - author { - id - handle - __typename - } - __typename - } - __typename - } - }` - ) - .withVariables({ - id: '0b58959d-d448-4a4e-84b6-35e5ac0028d1' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - data: { - topic: { - id: like('0b58959d-d448-4a4e-84b6-35e5ac0028d1'), - title: like('The pacty topic of the day'), - updated_at: like(1619979888906), - ttl: like(3399), - forum: { - id: like('cucumber'), - glyph: like('✽'), - label: like('test_forums.cucumber') - }, - tags: eachLike({ - id: like('skunk'), - weight: like(44) - }), - posts: eachLike({ - id: like('ed93530e-6f9c-4701-91ef-14f9e0ed3e26'), - text: like('The content of this post is very relevant'), - created_at: like(1619979889798), - author: like({ - id: like('07fb2ba0-0945-464a-b215-873296710c8c'), - handle: like('cucumber_fan92') - }) - }) - } - } - } - }); - return await internals.provider.addInteraction(topicQuery); - }); - - test('it returns the topic', async () => { - - const topic = getTopic('0b58959d-d448-4a4e-84b6-35e5ac0028d1'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - topic.subscribe((topicValue) => { - - response = topicValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toEqual({ - id: '0b58959d-d448-4a4e-84b6-35e5ac0028d1', - title: 'The pacty topic of the day', - updated_at: 1619979888906, - ttl: 3399, - forum: { - id: 'cucumber', - glyph: '✽', - label: 'test_forums.cucumber' - }, - tags: [{ - id: 'skunk', - weight: 44 - }], - posts: [{ - id: 'ed93530e-6f9c-4701-91ef-14f9e0ed3e26', - text: 'The content of this post is very relevant', - created_at: 1619979889798, - author: { - id: '07fb2ba0-0945-464a-b215-873296710c8c', - handle: 'cucumber_fan92' - } - }] - }); - expect(response.loading).toBe(false); - expect(response.error).toBe(undefined); - }); - }); - }); - - describe('When there\'s no data', () => { - - describe('GetTopic', () => { - - beforeAll(async () => { - - const topicQuery = new GraphQLInteraction() - .given('there\'s no data') - .uponReceiving('a request to get a single topic') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetTopic') - .withQuery( - `query GetTopic($id: ID!) { - topic(id: $id) { - id - title - updated_at - ttl - forum { - id - glyph - label - __typename - } - tags { - id - weight - __typename - } - posts { - id - text - created_at - author { - id - handle - __typename - } - __typename - } - __typename - } - }` - ) - .withVariables({ - id: '0b58959d-d448-4a4e-84b6-35e5ac0028d1' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - data: { - topic: null - } - } - }); - return await internals.provider.addInteraction(topicQuery); - }); - - test('it returns the topic', async () => { - - const topic = getTopic('0b58959d-d448-4a4e-84b6-35e5ac0028d1'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - topic.subscribe((topicValue) => { - - response = topicValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error).toBe(undefined); - }); - }); - }); - - describe('When there\'s a server error', () => { - - describe('GetTopic', () => { - - beforeAll(async () => { - - const topicQuery = new GraphQLInteraction() - .given('there\'s a server error') - .uponReceiving('a request to get a single topic') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetTopic') - .withQuery( - `query GetTopic($id: ID!) { - topic(id: $id) { - id - title - updated_at - ttl - forum { - id - glyph - label - __typename - } - tags { - id - weight - __typename - } - posts { - id - text - created_at - author { - id - handle - __typename - } - __typename - } - __typename - } - }` - ) - .withVariables({ - id: '0b58959d-d448-4a4e-84b6-35e5ac0028d1' - }) - .willRespondWith({ - status: 500 - }); - return await internals.provider.addInteraction(topicQuery); - }); - - test('it returns the error', async () => { - - const topic = getTopic('0b58959d-d448-4a4e-84b6-35e5ac0028d1'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - topic.subscribe((topicValue) => { - - response = topicValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error).toBeInstanceOf(Error); - }); - }); - }); - - describe('When there\'s an error in the response', () => { - - describe('GetTopic', () => { - - beforeAll(async () => { - - const topicQuery = new GraphQLInteraction() - .given('there\'s an error in the response') - .uponReceiving('a request to get a single topic') - .withRequest({ - path: '/graphql', - method: 'POST' - }) - .withOperation('GetTopic') - .withQuery( - `query GetTopic($id: ID!) { - topic(id: $id) { - id - title - updated_at - ttl - forum { - id - glyph - label - __typename - } - tags { - id - weight - __typename - } - posts { - id - text - created_at - author { - id - handle - __typename - } - __typename - } - __typename - } - }` - ) - .withVariables({ - id: '0b58959d-d448-4a4e-84b6-35e5ac0028d1' - }) - .willRespondWith({ - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: { - errors: eachLike({ - message: like('An error occurred when fetching the topic') - }) - } - }); - return await internals.provider.addInteraction(topicQuery); - }); - - test('it returns the error', async () => { - - const topic = getTopic('0b58959d-d448-4a4e-84b6-35e5ac0028d1'); - const { counter, promise: resolveAfterTwo } = resolveAfter(2); - let response = null; - topic.subscribe((topicValue) => { - - response = topicValue; - counter(); - }); - expect(response.data).toBe(null); - expect(response.loading).toBe(true); - expect(response.error).toBe(undefined); - await resolveAfterTwo; - expect(response.data).toBe(null); - expect(response.loading).toBe(false); - expect(response.error.graphQLErrors).toEqual(expect.arrayContaining([{ - message: 'An error occurred when fetching the topic' - }])); - }); - }); - }); -}); |