]> git.r.bdr.sh - rbdr/forum/blobdiff - src/lib/stores/tags.test.ts
Don't remember what this WIP was about
[rbdr/forum] / src / lib / stores / tags.test.ts
index 9d3eb5086d453d098acea346c4c19ecb9e33fdea..8c9effe1a1b498a5f7446fb715010da5433cb6ac 100644 (file)
@@ -10,43 +10,38 @@ jest.mock('$lib/config/config.ts');
 import { getTag } from './tags';
 
 const internals = {
-  provider: null
+       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!) {
+       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 {
@@ -59,77 +54,74 @@ describe('Tags store pact', () => {
                 __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!) {
+                                       )
+                                       .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 {
@@ -142,61 +134,56 @@ describe('Tags store pact', () => {
                 __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!) {
+                                       )
+                                       .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 {
@@ -209,53 +196,48 @@ describe('Tags store pact', () => {
                 __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!) {
+                                       )
+                                       .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 {
@@ -268,44 +250,46 @@ describe('Tags store pact', () => {
                 __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'
-        }]));
-      });
-    });
-  });
+                                       )
+                                       .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'
+                                               }
+                                       ])
+                               );
+                       });
+               });
+       });
 });