From 7dc46e280eee7bb7da14bad86a1f8d8e2d826480 Mon Sep 17 00:00:00 2001 From: kim Date: Tue, 31 Oct 2023 15:54:14 +0100 Subject: [PATCH] refactor: remove js cookie --- package.json | 2 -- src/hooks/action.test.ts | 2 -- src/hooks/apps.test.ts | 2 -- src/hooks/category.test.ts | 3 --- src/hooks/chat.test.ts | 14 +++++--------- src/hooks/invitation.test.ts | 3 --- src/hooks/item.test.ts | 2 -- src/hooks/itemLike.test.ts | 2 -- src/hooks/itemTag.test.ts | 3 --- src/hooks/itemValidation.test.ts | 3 --- src/hooks/member.test.ts | 2 -- src/hooks/membership.test.ts | 2 -- src/hooks/mention.test.ts | 3 --- src/mutations/action.test.ts | 3 --- src/mutations/authentication.test.ts | 3 --- src/mutations/chat.test.ts | 29 +++++++++++++--------------- src/mutations/invitation.test.ts | 3 --- src/mutations/item.test.ts | 3 --- src/mutations/itemCategory.test.ts | 3 --- src/mutations/itemExport.test.ts | 3 --- src/mutations/itemFlag.test.ts | 2 -- src/mutations/itemLike.test.ts | 2 -- src/mutations/itemLogin.test.ts | 2 -- src/mutations/itemPublish.test.ts | 3 --- src/mutations/itemTag.test.ts | 3 --- src/mutations/itemValidation.test.ts | 3 --- src/mutations/member.test.ts | 3 --- src/mutations/membership.test.ts | 3 --- src/mutations/mention.test.ts | 3 --- src/routines/chat.ts | 8 ++++---- src/ws/hooks/chat.test.ts | 20 +++++++++---------- src/ws/hooks/item.test.ts | 4 ---- src/ws/hooks/membership.test.ts | 4 ---- test/constants.ts | 10 ++-------- yarn.lock | 9 --------- 35 files changed, 34 insertions(+), 135 deletions(-) diff --git a/package.json b/package.json index ec7bcdb04..72745e0bd 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "@trivago/prettier-plugin-sort-imports": "4.2.1", "@types/crypto-js": "4.1.3", "@types/jest": "29.5.6", - "@types/js-cookie": "3.0.5", "@types/jsdom": "21.1.4", "@types/node": "20.8.8", "@types/qs": "6.9.9", @@ -62,7 +61,6 @@ "husky": "8.0.3", "jest": "29.7.0", "jest-environment-jsdom": "29.7.0", - "js-cookie": "3.0.5", "mock-socket": "9.3.1", "nock": "13.3.6", "prettier": "3.0", diff --git a/src/hooks/action.test.ts b/src/hooks/action.test.ts index 2728d0749..9b77e754d 100644 --- a/src/hooks/action.test.ts +++ b/src/hooks/action.test.ts @@ -9,7 +9,6 @@ import { } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -30,7 +29,6 @@ type AggregateActionsResponse = { const { hooks, wrapper, queryClient } = setUpTest(); const itemId = ITEMS[0].id; -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); describe('Action Hooks', () => { afterEach(() => { nock.cleanAll(); diff --git a/src/hooks/apps.test.ts b/src/hooks/apps.test.ts index 395b4c0ec..39ef66cbe 100644 --- a/src/hooks/apps.test.ts +++ b/src/hooks/apps.test.ts @@ -2,7 +2,6 @@ import { App } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { APPS, UNAUTHORIZED_RESPONSE } from '../../test/constants'; @@ -12,7 +11,6 @@ import { APPS_KEY } from '../config/keys'; const { hooks, wrapper, queryClient } = setUpTest(); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); describe('Apps Hooks', () => { afterEach(() => { nock.cleanAll(); diff --git a/src/hooks/category.test.ts b/src/hooks/category.test.ts index bc9184cf7..648b4fe61 100644 --- a/src/hooks/category.test.ts +++ b/src/hooks/category.test.ts @@ -1,6 +1,5 @@ /* eslint-disable import/no-extraneous-dependencies */ import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -24,8 +23,6 @@ import { const { hooks, wrapper, queryClient } = setUpTest(); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Category Hooks', () => { afterEach(() => { nock.cleanAll(); diff --git a/src/hooks/chat.test.ts b/src/hooks/chat.test.ts index 2065644e2..ce2485607 100644 --- a/src/hooks/chat.test.ts +++ b/src/hooks/chat.test.ts @@ -1,8 +1,7 @@ /* eslint-disable import/no-extraneous-dependencies */ -import { ChatMessage, ItemChat } from '@graasp/sdk'; +import { ChatMessage } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -10,7 +9,6 @@ import { MOCK_ITEM, MOCK_MEMBER, UNAUTHORIZED_RESPONSE, - createMockItemChat, } from '../../test/constants'; import { mockHook, setUpTest } from '../../test/utils'; import { buildGetItemChatRoute } from '../api/routes'; @@ -18,8 +16,6 @@ import { buildItemChatKey } from '../config/keys'; const { hooks, wrapper, queryClient } = setUpTest(); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Chat Hooks', () => { afterEach(() => { nock.cleanAll(); @@ -27,7 +23,7 @@ describe('Chat Hooks', () => { }); describe('useItemChat', () => { - const itemId = ITEMS_JS[0].id; + const itemId = ITEMS[0].id; const mockMessage: ChatMessage = { id: 'some-messageId', item: MOCK_ITEM, @@ -42,7 +38,7 @@ describe('Chat Hooks', () => { const hook = () => hooks.useItemChat(itemId); it(`Receive chat messages`, async () => { - const response: ItemChat = createMockItemChat([mockMessage]); + const response = [mockMessage]; const endpoints = [ { route, @@ -98,7 +94,7 @@ describe('Chat Hooks', () => { it(`getUpdates = true`, async () => { const hook = () => hooks.useItemChat(itemId, { getUpdates: true }); - const response = createMockItemChat([mockMessage]); + const response = [mockMessage]; const endpoints = [ { route, @@ -119,7 +115,7 @@ describe('Chat Hooks', () => { it(`getUpdates = false`, async () => { const hook = () => hooks.useItemChat(itemId, { getUpdates: false }); - const response = createMockItemChat([mockMessage]); + const response = [mockMessage]; const endpoints = [ { route, diff --git a/src/hooks/invitation.test.ts b/src/hooks/invitation.test.ts index 590239461..3cb2cb72f 100644 --- a/src/hooks/invitation.test.ts +++ b/src/hooks/invitation.test.ts @@ -1,6 +1,5 @@ /* eslint-disable import/no-extraneous-dependencies */ import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -18,8 +17,6 @@ import { buildInvitationKey, buildItemInvitationsKey } from '../config/keys'; const { hooks, wrapper, queryClient } = setUpTest(); const item = ITEMS[0]; -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Invitation Hooks', () => { afterEach(() => { nock.cleanAll(); diff --git a/src/hooks/item.test.ts b/src/hooks/item.test.ts index 21efc6ae4..9832033a6 100644 --- a/src/hooks/item.test.ts +++ b/src/hooks/item.test.ts @@ -8,7 +8,6 @@ import { } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -47,7 +46,6 @@ import { } from '../config/keys'; const { hooks, wrapper, queryClient } = setUpTest(); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); describe('Items Hooks', () => { afterEach(() => { diff --git a/src/hooks/itemLike.test.ts b/src/hooks/itemLike.test.ts index b5176fef3..4a59a8157 100644 --- a/src/hooks/itemLike.test.ts +++ b/src/hooks/itemLike.test.ts @@ -1,7 +1,6 @@ import { ItemLike } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { ITEMS, ITEM_LIKES, UNAUTHORIZED_RESPONSE } from '../../test/constants'; @@ -16,7 +15,6 @@ import { } from '../config/keys'; const { hooks, wrapper, queryClient } = setUpTest(); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); describe('Item Like Hooks', () => { afterEach(() => { diff --git a/src/hooks/itemTag.test.ts b/src/hooks/itemTag.test.ts index 6292ca488..c730e7386 100644 --- a/src/hooks/itemTag.test.ts +++ b/src/hooks/itemTag.test.ts @@ -7,7 +7,6 @@ import { } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -27,8 +26,6 @@ import { itemTagsKeys } from '../config/keys'; const { hooks, wrapper, queryClient } = setUpTest(); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Item Tags Hooks', () => { afterEach(() => { nock.cleanAll(); diff --git a/src/hooks/itemValidation.test.ts b/src/hooks/itemValidation.test.ts index 977b88393..c106e6f5c 100644 --- a/src/hooks/itemValidation.test.ts +++ b/src/hooks/itemValidation.test.ts @@ -1,5 +1,4 @@ import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -12,8 +11,6 @@ import { buildLastItemValidationGroupKey } from '../config/keys'; const { hooks, wrapper, queryClient } = setUpTest(); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Item Validation Hooks', () => { afterEach(() => { nock.cleanAll(); diff --git a/src/hooks/member.test.ts b/src/hooks/member.test.ts index 00e1eb308..7226e0411 100644 --- a/src/hooks/member.test.ts +++ b/src/hooks/member.test.ts @@ -8,7 +8,6 @@ import { } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -38,7 +37,6 @@ import { } from '../config/keys'; const { hooks, wrapper, queryClient } = setUpTest(); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); describe('Member Hooks', () => { afterEach(() => { queryClient.clear(); diff --git a/src/hooks/membership.test.ts b/src/hooks/membership.test.ts index fb8231e3b..57e540b74 100644 --- a/src/hooks/membership.test.ts +++ b/src/hooks/membership.test.ts @@ -6,7 +6,6 @@ import { } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -23,7 +22,6 @@ import { } from '../config/keys'; const { hooks, wrapper, queryClient } = setUpTest(); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); describe('Membership Hooks', () => { afterEach(() => { diff --git a/src/hooks/mention.test.ts b/src/hooks/mention.test.ts index 461e20cb8..21b0642ad 100644 --- a/src/hooks/mention.test.ts +++ b/src/hooks/mention.test.ts @@ -1,5 +1,4 @@ /* eslint-disable import/no-extraneous-dependencies */ -import Cookies from 'js-cookie'; import nock from 'nock'; import { MEMBER_RESPONSE, buildMemberMentions } from '../../test/constants'; @@ -12,8 +11,6 @@ import { buildMentionKey } from '../config/keys'; const { hooks, wrapper, queryClient } = setUpTest(); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Chat Mention Hooks', () => { afterEach(() => { nock.cleanAll(); diff --git a/src/mutations/action.test.ts b/src/mutations/action.test.ts index ad8b8cfab..1476ee36d 100644 --- a/src/mutations/action.test.ts +++ b/src/mutations/action.test.ts @@ -2,7 +2,6 @@ import { HttpMethod } from '@graasp/sdk'; import { act } from '@testing-library/react'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -14,8 +13,6 @@ import { mockMutation, setUpTest, waitForMutation } from '../../test/utils'; import { buildExportActions, buildPostItemAction } from '../api/routes'; import { exportActionsRoutine, postActionRoutine } from '../routines'; -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Action Mutations', () => { const itemId = ITEMS[0].id; diff --git a/src/mutations/authentication.test.ts b/src/mutations/authentication.test.ts index d13085a5f..35645c071 100644 --- a/src/mutations/authentication.test.ts +++ b/src/mutations/authentication.test.ts @@ -5,7 +5,6 @@ import { SUCCESS_MESSAGES } from '@graasp/translations'; import { act } from '@testing-library/react'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { OK_RESPONSE, UNAUTHORIZED_RESPONSE } from '../../test/constants'; @@ -47,8 +46,6 @@ jest.mock('@graasp/sdk', () => { }; }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - const captcha = 'captcha'; const email = 'myemail@email.com'; const challenge = '1234'; diff --git a/src/mutations/chat.test.ts b/src/mutations/chat.test.ts index ae019c372..673d8ab48 100644 --- a/src/mutations/chat.test.ts +++ b/src/mutations/chat.test.ts @@ -3,12 +3,11 @@ import { HttpMethod } from '@graasp/sdk'; import { act } from '@testing-library/react'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { + CHAT_MESSAGES, ITEMS, - ITEM_CHAT, MESSAGE_IDS, OK_RESPONSE, UNAUTHORIZED_RESPONSE, @@ -28,8 +27,6 @@ import { postItemChatMessageRoutine, } from '../routines'; -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Chat Mutations', () => { const itemId = ITEMS[0].id; const chatKey = buildItemChatKey(itemId); @@ -55,7 +52,7 @@ describe('Chat Mutations', () => { { route, response: OK_RESPONSE, method: HttpMethod.POST }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -82,7 +79,7 @@ describe('Chat Mutations', () => { }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -114,7 +111,7 @@ describe('Chat Mutations', () => { { route, response: OK_RESPONSE, method: HttpMethod.PATCH }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -145,7 +142,7 @@ describe('Chat Mutations', () => { }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -182,7 +179,7 @@ describe('Chat Mutations', () => { { route, response: OK_RESPONSE, method: HttpMethod.DELETE }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -209,7 +206,7 @@ describe('Chat Mutations', () => { }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -241,7 +238,7 @@ describe('Chat Mutations', () => { { route, response: OK_RESPONSE, method: HttpMethod.DELETE }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -268,7 +265,7 @@ describe('Chat Mutations', () => { }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -310,7 +307,7 @@ describe('Chat Mutations', () => { { route, response: OK_RESPONSE, method: HttpMethod.POST }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -337,7 +334,7 @@ describe('Chat Mutations', () => { { route, response: OK_RESPONSE, method: HttpMethod.PATCH }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -368,7 +365,7 @@ describe('Chat Mutations', () => { { route, response: OK_RESPONSE, method: HttpMethod.DELETE }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, @@ -398,7 +395,7 @@ describe('Chat Mutations', () => { { route, response: OK_RESPONSE, method: HttpMethod.DELETE }, ]; // set random data in cache - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); const mockedMutation = await mockMutation({ endpoints, diff --git a/src/mutations/invitation.test.ts b/src/mutations/invitation.test.ts index 20648fb79..93536b222 100644 --- a/src/mutations/invitation.test.ts +++ b/src/mutations/invitation.test.ts @@ -3,7 +3,6 @@ import { HttpMethod, Invitation } from '@graasp/sdk'; import { act } from '@testing-library/react'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -28,8 +27,6 @@ import { resendInvitationRoutine, } from '../routines'; -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - const item = ITEMS[0]; const itemId = item.id; diff --git a/src/mutations/item.test.ts b/src/mutations/item.test.ts index b981998cb..2aaa28914 100644 --- a/src/mutations/item.test.ts +++ b/src/mutations/item.test.ts @@ -12,7 +12,6 @@ import { SUCCESS_MESSAGES } from '@graasp/translations'; import { act } from '@testing-library/react'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -62,8 +61,6 @@ const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Items Mutations', () => { afterEach(() => { queryClient.clear(); diff --git a/src/mutations/itemCategory.test.ts b/src/mutations/itemCategory.test.ts index 5ace57b58..ae8a370b0 100644 --- a/src/mutations/itemCategory.test.ts +++ b/src/mutations/itemCategory.test.ts @@ -3,7 +3,6 @@ import { HttpMethod } from '@graasp/sdk'; import { SUCCESS_MESSAGES } from '@graasp/translations'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { act } from 'react-test-renderer'; @@ -24,8 +23,6 @@ const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Item Category Mutations', () => { afterEach(() => { queryClient.clear(); diff --git a/src/mutations/itemExport.test.ts b/src/mutations/itemExport.test.ts index ae95fa49c..429be33e0 100644 --- a/src/mutations/itemExport.test.ts +++ b/src/mutations/itemExport.test.ts @@ -1,7 +1,6 @@ /* eslint-disable import/no-extraneous-dependencies */ import { HttpMethod } from '@graasp/sdk'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { act } from 'react-test-renderer'; @@ -14,8 +13,6 @@ const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Export Zip', () => { afterEach(() => { queryClient.clear(); diff --git a/src/mutations/itemFlag.test.ts b/src/mutations/itemFlag.test.ts index b8b6ddce7..03e95d216 100644 --- a/src/mutations/itemFlag.test.ts +++ b/src/mutations/itemFlag.test.ts @@ -3,7 +3,6 @@ import { FlagType, HttpMethod } from '@graasp/sdk'; import { SUCCESS_MESSAGES } from '@graasp/translations'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { act } from 'react-test-renderer'; @@ -17,7 +16,6 @@ const mockedNotifier = jest.fn(); const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); describe('Item Flag Mutations', () => { afterEach(() => { diff --git a/src/mutations/itemLike.test.ts b/src/mutations/itemLike.test.ts index 0f5ef2c00..817911edc 100644 --- a/src/mutations/itemLike.test.ts +++ b/src/mutations/itemLike.test.ts @@ -1,7 +1,6 @@ import { HttpMethod } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { act } from 'react-test-renderer'; @@ -23,7 +22,6 @@ const mockedNotifier = jest.fn(); const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); describe('Item Like Mutations', () => { afterEach(() => { diff --git a/src/mutations/itemLogin.test.ts b/src/mutations/itemLogin.test.ts index a4803483b..f47a61927 100644 --- a/src/mutations/itemLogin.test.ts +++ b/src/mutations/itemLogin.test.ts @@ -2,7 +2,6 @@ import { HttpMethod, ItemLoginSchemaType } from '@graasp/sdk'; import { SUCCESS_MESSAGES } from '@graasp/translations'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { act } from 'react-test-renderer'; @@ -27,7 +26,6 @@ const mockedNotifier = jest.fn(); const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); describe('Item Login Mutations', () => { afterEach(() => { diff --git a/src/mutations/itemPublish.test.ts b/src/mutations/itemPublish.test.ts index fc9ccfbfd..37131554b 100644 --- a/src/mutations/itemPublish.test.ts +++ b/src/mutations/itemPublish.test.ts @@ -2,7 +2,6 @@ import { HttpMethod } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { act } from 'react-test-renderer'; @@ -27,8 +26,6 @@ const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Publish Item', () => { afterEach(() => { queryClient.clear(); diff --git a/src/mutations/itemTag.test.ts b/src/mutations/itemTag.test.ts index 018f6dd3a..bae1db490 100644 --- a/src/mutations/itemTag.test.ts +++ b/src/mutations/itemTag.test.ts @@ -2,7 +2,6 @@ import { HttpMethod, ItemTagType } from '@graasp/sdk'; import { SUCCESS_MESSAGES } from '@graasp/translations'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { act } from 'react-test-renderer'; @@ -22,8 +21,6 @@ const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Item Tag Mutations', () => { afterEach(() => { queryClient.clear(); diff --git a/src/mutations/itemValidation.test.ts b/src/mutations/itemValidation.test.ts index d3d7b49c0..0d8484284 100644 --- a/src/mutations/itemValidation.test.ts +++ b/src/mutations/itemValidation.test.ts @@ -1,7 +1,6 @@ import { HttpMethod } from '@graasp/sdk'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { act } from 'react-test-renderer'; @@ -19,8 +18,6 @@ const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Item Validation Mutations', () => { afterEach(() => { queryClient.clear(); diff --git a/src/mutations/member.test.ts b/src/mutations/member.test.ts index 540e90da6..adcabe89a 100644 --- a/src/mutations/member.test.ts +++ b/src/mutations/member.test.ts @@ -3,7 +3,6 @@ import { SUCCESS_MESSAGES } from '@graasp/translations'; import { act } from '@testing-library/react'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -22,8 +21,6 @@ import { import { CURRENT_MEMBER_KEY, buildAvatarKey } from '../config/keys'; import { uploadAvatarRoutine } from '../routines'; -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - const mockedNotifier = jest.fn(); const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, diff --git a/src/mutations/membership.test.ts b/src/mutations/membership.test.ts index 42f97a2c5..b75cb5a88 100644 --- a/src/mutations/membership.test.ts +++ b/src/mutations/membership.test.ts @@ -5,7 +5,6 @@ import { HttpMethod, ItemMembership, PermissionLevel } from '@graasp/sdk'; import { SUCCESS_MESSAGES } from '@graasp/translations'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { act } from 'react-test-renderer'; @@ -50,8 +49,6 @@ const { wrapper, queryClient, mutations } = setUpTest({ notifier: mockedNotifier, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Membership Mutations', () => { afterEach(() => { queryClient.clear(); diff --git a/src/mutations/mention.test.ts b/src/mutations/mention.test.ts index aacb854ba..df36e1115 100644 --- a/src/mutations/mention.test.ts +++ b/src/mutations/mention.test.ts @@ -2,7 +2,6 @@ import { HttpMethod, MentionStatus } from '@graasp/sdk'; import { act } from '@testing-library/react'; import { StatusCodes } from 'http-status-codes'; -import Cookies from 'js-cookie'; import nock from 'nock'; import { @@ -28,8 +27,6 @@ import { patchMentionRoutine, } from '../routines'; -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Mention Mutations', () => { const mentionId = MENTION_IDS[0]; const member = MEMBER_RESPONSE; diff --git a/src/routines/chat.ts b/src/routines/chat.ts index 2191f99ba..1702a73b4 100644 --- a/src/routines/chat.ts +++ b/src/routines/chat.ts @@ -1,15 +1,15 @@ import createRoutine from './utils'; export const postItemChatMessageRoutine = createRoutine( - 'POST_ITEM_CHAT_MESSAGE', + 'POST_CHAT_MESSAGES_MESSAGE', ); export const patchItemChatMessageRoutine = createRoutine( - 'PATCH_ITEM_CHAT_MESSAGE', + 'PATCH_CHAT_MESSAGES_MESSAGE', ); export const deleteItemChatMessageRoutine = createRoutine( - 'DELETE_ITEM_CHAT_MESSAGE', + 'DELETE_CHAT_MESSAGES_MESSAGE', ); -export const clearItemChatRoutine = createRoutine('CLEAR_ITEM_CHAT'); +export const clearItemChatRoutine = createRoutine('CLEAR_CHAT_MESSAGES'); diff --git a/src/ws/hooks/chat.test.ts b/src/ws/hooks/chat.test.ts index eb1823c05..cd6413457 100644 --- a/src/ws/hooks/chat.test.ts +++ b/src/ws/hooks/chat.test.ts @@ -1,6 +1,6 @@ import { ChatMessage } from '@graasp/sdk'; -import { ITEMS, ITEM_CHAT, MESSAGE_IDS } from '../../../test/constants'; +import { CHAT_MESSAGES, ITEMS, MESSAGE_IDS } from '../../../test/constants'; import { getHandlerByChannel, mockWsHook, @@ -29,7 +29,7 @@ describe('Ws Chat Hooks', () => { }; it('Does nothing', async () => { - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); await mockWsHook({ hook: incorrectHook, wrapper, @@ -44,7 +44,7 @@ describe('Ws Chat Hooks', () => { getHandlerByChannel(handlers, channel)?.handler(chatEvent); // expect no change - expect(queryClient.getQueryData(chatKey)).toEqual(ITEM_CHAT); + expect(queryClient.getQueryData(chatKey)).toEqual(CHAT_MESSAGES); }); }); @@ -60,7 +60,7 @@ describe('Ws Chat Hooks', () => { const hook = () => hooks.useItemChatUpdates(itemId); it(`Receive chat messages update`, async () => { - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); await mockWsHook({ hook, wrapper, @@ -82,7 +82,7 @@ describe('Ws Chat Hooks', () => { id: MESSAGE_IDS[0], body: 'new message content', }; - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); await mockWsHook({ hook, wrapper, @@ -100,7 +100,7 @@ describe('Ws Chat Hooks', () => { it(`Receive chat messages delete update`, async () => { const deletedMessage = { id: MESSAGE_IDS[0] }; - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); await mockWsHook({ hook, wrapper, @@ -115,11 +115,11 @@ describe('Ws Chat Hooks', () => { getHandlerByChannel(handlers, channel)?.handler(chatEvent); const m = queryClient.getQueryData(chatKey); expect(m).toHaveLength(1); - expect(m).not.toContainEqual(ITEM_CHAT.messages[0]); + expect(m).not.toContainEqual(CHAT_MESSAGES[0]); }); it(`Receive chat messages clear update`, async () => { - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); await mockWsHook({ hook, wrapper, @@ -136,7 +136,7 @@ describe('Ws Chat Hooks', () => { }); it(`Does not update chat messages with wrong chat event`, async () => { - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); await mockWsHook({ hook, wrapper, @@ -158,7 +158,7 @@ describe('Ws Chat Hooks', () => { }); it(`Does not update chat messages with wrong OP event`, async () => { - queryClient.setQueryData(chatKey, ITEM_CHAT); + queryClient.setQueryData(chatKey, CHAT_MESSAGES); await mockWsHook({ hook, wrapper, diff --git a/src/ws/hooks/item.test.ts b/src/ws/hooks/item.test.ts index a8d96cc15..5f6440182 100644 --- a/src/ws/hooks/item.test.ts +++ b/src/ws/hooks/item.test.ts @@ -1,7 +1,5 @@ import { DiscriminatedItem, Item } from '@graasp/sdk'; -import Cookies from 'js-cookie'; - import { ITEMS } from '../../../test/constants'; import { getHandlerByChannel, @@ -21,8 +19,6 @@ const { hooks, wrapper, queryClient, handlers } = setUpWsTest({ configureWsHooks: configureWsItemHooks, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Ws Item Hooks', () => { afterEach(() => { queryClient.clear(); diff --git a/src/ws/hooks/membership.test.ts b/src/ws/hooks/membership.test.ts index 456866f5c..b4ebfc1e4 100644 --- a/src/ws/hooks/membership.test.ts +++ b/src/ws/hooks/membership.test.ts @@ -1,7 +1,5 @@ import { ItemMembership, PermissionLevel } from '@graasp/sdk'; -import Cookies from 'js-cookie'; - import { ITEMS, ITEM_MEMBERSHIPS_RESPONSE } from '../../../test/constants'; import { getHandlerByChannel, @@ -16,8 +14,6 @@ const { hooks, wrapper, queryClient, handlers } = setUpWsTest({ configureWsHooks: configureWsMembershipHooks, }); -jest.spyOn(Cookies, 'get').mockReturnValue({ session: 'somesession' }); - describe('Ws Membership Hooks', () => { afterEach(() => { queryClient.clear(); diff --git a/test/constants.ts b/test/constants.ts index c30081eb0..50f217947 100644 --- a/test/constants.ts +++ b/test/constants.ts @@ -16,7 +16,6 @@ import { HttpMethod, Invitation, ItemCategory, - ItemChat, ItemFavorite, ItemFlag, ItemLike, @@ -377,11 +376,6 @@ export const createMockMemberMentions = ( ...memberMentions, }); -export const createMockItemChat = (messages?: ChatMessage[]): ItemChat => ({ - messages: messages ?? [], - id: 'someid', -}); - export const buildChatMention = ({ id = v4(), member = MOCK_MEMBER, @@ -468,7 +462,7 @@ const ITEM_TAG_2: ItemTag = createMockItemTags({ export const ITEM_TAGS = [ITEM_TAG_1, ITEM_TAG_2]; -export const ITEM_CHAT: ItemChat = createMockItemChat([ +export const CHAT_MESSAGES: ChatMessage[] = [ { id: MESSAGE_IDS[0], item: ITEM_1, @@ -485,7 +479,7 @@ export const ITEM_CHAT: ItemChat = createMockItemChat([ updatedAt: '2023-09-06T11:50:32.894Z', body: 'text of second message', }, -]); +]; const defaultCategoryValues: Category = { id: 'category-id1', diff --git a/yarn.lock b/yarn.lock index cf78a66c5..d2016b511 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2397,7 +2397,6 @@ __metadata: "@trivago/prettier-plugin-sort-imports": "npm:4.2.1" "@types/crypto-js": "npm:4.1.3" "@types/jest": "npm:29.5.6" - "@types/js-cookie": "npm:3.0.5" "@types/jsdom": "npm:21.1.4" "@types/node": "npm:20.8.8" "@types/qs": "npm:6.9.9" @@ -2423,7 +2422,6 @@ __metadata: husky: "npm:8.0.3" jest: "npm:29.7.0" jest-environment-jsdom: "npm:29.7.0" - js-cookie: "npm:3.0.5" mock-socket: "npm:9.3.1" nock: "npm:13.3.6" prettier: "npm:3.0" @@ -3674,13 +3672,6 @@ __metadata: languageName: node linkType: hard -"@types/js-cookie@npm:3.0.5": - version: 3.0.5 - resolution: "@types/js-cookie@npm:3.0.5" - checksum: 4d91ae26445499fdde283928aac9ad149be3561ef9b4d959f77e44694608accd5939c8c68ba42c50c2cfc007ccd442cc566a41077d7f2766390088fa91b612ce - languageName: node - linkType: hard - "@types/jsdom@npm:21.1.4": version: 21.1.4 resolution: "@types/jsdom@npm:21.1.4"