From a88d155dd753ec06ed26468e6c907e4403210600 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 27 Sep 2023 14:02:34 +0530 Subject: [PATCH] feat: update tool-chain to latest (#7975) Co-authored-by: Pranav Raj S --- .eslintrc.js | 10 +- app/javascript/dashboard/App.vue | 6 +- app/javascript/dashboard/api/ApiClient.js | 5 +- app/javascript/dashboard/api/contacts.js | 1 + .../api/enterprise/specs/account.spec.js | 23 +- app/javascript/dashboard/api/reports.js | 1 + .../dashboard/api/specs/account.spec.js | 21 +- .../api/specs/accountActions.spec.js | 21 +- .../dashboard/api/specs/apiSpecHelper.js | 27 - .../dashboard/api/specs/article.spec.js | 81 +- .../api/specs/assignableAgents.spec.js | 32 +- .../api/specs/channel/fbChannel.spec.js | 23 +- .../dashboard/api/specs/contacts.spec.js | 48 +- .../dashboard/api/specs/conversations.spec.js | 23 +- .../dashboard/api/specs/csatReports.spec.js | 25 +- .../api/specs/inbox/conversation.spec.js | 89 +- .../dashboard/api/specs/inbox/message.spec.js | 26 +- .../dashboard/api/specs/inboxes.spec.js | 28 +- .../dashboard/api/specs/integrations.spec.js | 33 +- .../api/specs/integrations/dyte.spec.js | 41 +- .../dashboard/api/specs/notifications.spec.js | 29 +- .../dashboard/api/specs/reports.spec.js | 110 +- .../dashboard/api/specs/teams.spec.js | 25 +- .../dashboard/components/ChatList.vue | 13 +- .../components/CustomSnoozeModal.vue | 4 +- .../dashboard/components/MaskedText.vue | 2 +- app/javascript/dashboard/components/Modal.vue | 6 +- .../dashboard/components/SettingsSection.vue | 3 +- .../components/app/PaymentPendingBanner.vue | 6 +- .../components/app/versionCheckHelper.js | 2 +- .../components/buttons/ResolveAction.vue | 10 +- .../sidebarComponents/AddAccountModal.vue | 4 +- .../sidebarComponents/NotificationBell.vue | 3 +- .../SecondaryChildNavItem.vue | 6 +- .../sidebarComponents/SecondaryNavItem.vue | 3 +- .../dashboard/components/widgets/AILoader.vue | 2 +- .../components/widgets/FilterInput/Index.vue | 3 + .../components/widgets/WootWriter/Editor.vue | 2 + .../widgets/WootWriter/FullEditor.vue | 2 + .../conversation/AvailabilityStatusBadge.vue | 4 +- .../conversation/ConversationBasicFilter.vue | 4 +- .../widgets/conversation/ConversationCard.vue | 4 +- .../conversation/EmailTranscriptModal.vue | 1 + .../widgets/conversation/MessagesView.vue | 10 +- .../widgets/conversation/PriorityMark.vue | 6 +- .../widgets/conversation/ReplyBox.vue | 5 +- .../conversation/WhatsappTemplates/Modal.vue | 1 + .../widgets/conversation/bubble/Actions.vue | 5 +- .../conversation/bubble/integrations/Dyte.vue | 5 +- .../conversation/components/GalleryView.vue | 10 +- .../conversation/contextMenu/Index.vue | 16 +- .../widgets/forms/AvatarUploader.vue | 2 +- .../components/widgets/forms/PhoneInput.vue | 3 +- .../widgets/modal/ConfirmDeleteModal.vue | 1 + .../components/widgets/modal/DeleteModal.vue | 1 + .../widgets/modal/WootKeyShortcutModal.vue | 12 +- .../DashboardAudioNotificationHelper.js | 1 + app/javascript/dashboard/helper/URLHelper.js | 3 +- .../dashboard/helper/actionCable.js | 4 + .../dashboard/helper/automationHelper.js | 2 + .../dashboard/helper/customViewsHelper.js | 11 +- .../dashboard/helper/routeHelpers.js | 2 + .../helper/specs/auditlogHelper.spec.js | 18 +- .../helper/specs/editorHelper.spec.js | 10 +- .../mixins/automations/methodsMixin.js | 12 +- .../dashboard/mixins/specs/uiSettings.spec.js | 12 +- .../modules/contact/ContactMergeModal.vue | 1 + .../contact/components/AddCustomAttribute.vue | 1 + .../components/MessageContextMenu.vue | 12 +- .../modules/search/components/ReadMore.vue | 3 +- .../SearchResultConversationItem.vue | 2 +- .../components/WidgetFooter.vue | 4 +- .../dashboard/routes/dashboard/Dashboard.vue | 5 +- .../dashboard/commands/appearanceHotKeys.js | 5 +- .../routes/dashboard/commands/commandbar.vue | 14 +- .../contacts/components/ContactsView.vue | 7 +- .../conversation/ConversationAction.vue | 1 + .../conversation/ConversationInfo.vue | 6 +- .../conversation/ConversationView.vue | 13 +- .../conversation/Macros/MacroItem.vue | 2 +- .../conversation/contact/ContactForm.vue | 4 +- .../conversation/contact/CreateContact.vue | 1 + .../conversation/contact/EditContact.vue | 7 +- .../conversation/contact/NewConversation.vue | 1 + .../customviews/DeleteCustomViews.vue | 1 + .../helpcenter/components/AddLocale.vue | 1 + .../components/ArticleSearchResultItem.vue | 2 +- .../components/HelpCenterLayout.vue | 5 +- .../helpcenter/components/PortalSwitch.vue | 12 +- .../pages/categories/AddCategory.vue | 1 + .../pages/categories/EditCategory.vue | 1 + .../components/NotificationPanelList.vue | 6 +- .../dashboard/settings/account/Index.vue | 2 +- .../dashboard/settings/agents/AddAgent.vue | 9 +- .../dashboard/settings/agents/EditAgent.vue | 4 +- .../dashboard/settings/auditlogs/Index.vue | 12 +- .../dashboard/settings/canned/AddCanned.vue | 4 +- .../dashboard/settings/canned/EditCanned.vue | 4 +- .../dashboard/settings/inbox/FinishSetup.vue | 4 +- .../routes/dashboard/settings/inbox/Index.vue | 4 +- .../dashboard/settings/inbox/Settings.vue | 8 +- .../inbox/components/BotConfiguration.vue | 6 +- .../settings/integrationapps/NewHook.vue | 5 +- .../DashboardApps/DashboardAppsRow.vue | 8 +- .../settings/integrations/Integration.vue | 8 +- .../Slack/SlackIntegrationHelpText.vue | 2 +- .../settings/profile/ChangePassword.vue | 4 +- .../settings/profile/NotificationSettings.vue | 9 +- .../settings/reports/LiveReports.vue | 12 +- .../settings/reports/ReportContainer.vue | 5 +- .../components/ChartElements/ChartStats.vue | 4 +- .../reports/components/Filters/Labels.vue | 6 +- .../settings/reports/components/Heatmap.vue | 16 +- .../reports/components/ReportFilters.vue | 6 +- .../settings/teams/AgentSelector.vue | 4 +- app/javascript/dashboard/store/index.js | 3 +- .../dashboard/store/modules/accounts.js | 25 +- .../store/modules/contactConversations.js | 10 +- .../store/modules/contacts/actions.js | 6 +- .../store/modules/conversationWatchers.js | 5 +- .../dashboard/store/modules/customViews.js | 5 +- .../modules/helpCenterArticles/getters.js | 28 +- .../helpCenterArticles/specs/mutation.spec.js | 2 +- .../modules/helpCenterCategories/getters.js | 30 +- .../modules/helpCenterPortals/getters.js | 12 +- .../dashboard/store/modules/inboxes.js | 6 +- .../modules/specs/agents/mutations.spec.js | 2 +- .../components/ArticleSkeletonLoader.vue | 10 +- app/javascript/shared/components/TextArea.vue | 15 +- .../shared/components/emoji/EmojiInput.vue | 8 +- .../shared/helpers/AudioNotificationHelper.js | 2 + .../helpers/BaseActionCableConnector.js | 2 + app/javascript/shared/helpers/FileHelper.js | 2 +- .../helpers/specs/ReportsDataHelper.spec.js | 24 +- .../shared/mixins/globalConfigMixin.js | 1 + .../mixins/specs/automationMixin.spec.js | 2 + .../specs/whatsappTemplates/fixtures.js | 15 +- .../whatsappTemplates.spec.js | 7 +- app/javascript/v3/App.vue | 13 +- app/javascript/v3/components/Form/Input.vue | 5 +- .../v3/views/auth/password/Edit.vue | 4 +- .../widget/components/AgentMessage.vue | 5 +- .../components/ArticleCardSkeletonLoader.vue | 6 +- .../widget/components/ArticleListItem.vue | 2 +- .../widget/components/ChatHeader.vue | 6 +- .../widget/components/ChatInputWrap.vue | 4 +- .../widget/components/Form/PhoneInput.vue | 2 +- .../widget/components/GroupedAvatars.vue | 8 +- .../widget/components/HeaderActions.vue | 6 +- .../widget/components/TeamAvailability.vue | 2 +- .../components/template/IntegrationCard.vue | 9 +- .../widget/helpers/IframeEventHelper.js | 5 +- app/javascript/widget/helpers/actionCable.js | 7 +- .../widget/helpers/specs/utils.spec.js | 9 +- .../mixins/specs/nextAvailabilityTime.spec.js | 17 +- .../specs/conversation/actions.spec.js | 24 +- .../specs/conversation/mutations.spec.js | 10 +- app/javascript/widget/views/Home.vue | 10 +- babel.config.js | 15 +- jest.config.js | 17 +- package.json | 39 +- yarn.lock | 4775 +++++++++-------- 162 files changed, 3566 insertions(+), 2884 deletions(-) delete mode 100644 app/javascript/dashboard/api/specs/apiSpecHelper.js diff --git a/.eslintrc.js b/.eslintrc.js index 0fae1bc44..a58c77e98 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,7 +6,7 @@ module.exports = { 'plugin:storybook/recommended', ], parserOptions: { - parser: 'babel-eslint', + parser: '@babel/eslint-parser', ecmaVersion: 2020, sourceType: 'module', }, @@ -24,13 +24,16 @@ module.exports = { 'jsx-a11y/label-has-for': 'off', 'jsx-a11y/anchor-is-valid': 'off', 'import/no-unresolved': 'off', + 'vue/html-indent': 'off', + 'vue/multi-word-component-names': 'off', 'vue/max-attributes-per-line': [ 'error', { - singleline: 20, + singleline: { + max: 20, + }, multiline: { max: 1, - allowFirstLine: false, }, }, ], @@ -47,6 +50,7 @@ module.exports = { }, ], 'vue/no-v-html': 'off', + 'vue/component-definition-name-casing': 'off', 'vue/singleline-html-element-content-newline': 'off', 'import/extensions': ['off'], 'no-console': 'error', diff --git a/app/javascript/dashboard/App.vue b/app/javascript/dashboard/App.vue index 649d56d15..919167c2a 100644 --- a/app/javascript/dashboard/App.vue +++ b/app/javascript/dashboard/App.vue @@ -111,10 +111,8 @@ export default { this.$store.dispatch('setActiveAccount', { accountId: this.currentAccountId, }); - const { - locale, - latest_chatwoot_version: latestChatwootVersion, - } = this.getAccount(this.currentAccountId); + const { locale, latest_chatwoot_version: latestChatwootVersion } = + this.getAccount(this.currentAccountId); const { pubsub_token: pubsubToken } = this.currentUser || {}; this.setLocale(locale); this.updateRTLDirectionView(locale); diff --git a/app/javascript/dashboard/api/ApiClient.js b/app/javascript/dashboard/api/ApiClient.js index fed0746ca..6b57d32b6 100644 --- a/app/javascript/dashboard/api/ApiClient.js +++ b/app/javascript/dashboard/api/ApiClient.js @@ -15,9 +15,8 @@ class ApiClient { // eslint-disable-next-line class-methods-use-this get accountIdFromRoute() { - const isInsideAccountScopedURLs = window.location.pathname.includes( - '/app/accounts' - ); + const isInsideAccountScopedURLs = + window.location.pathname.includes('/app/accounts'); if (isInsideAccountScopedURLs) { return window.location.pathname.split('/')[3]; diff --git a/app/javascript/dashboard/api/contacts.js b/app/javascript/dashboard/api/contacts.js index 4def5ee2e..61312dd24 100644 --- a/app/javascript/dashboard/api/contacts.js +++ b/app/javascript/dashboard/api/contacts.js @@ -53,6 +53,7 @@ class ContactAPI extends ApiClient { return axios.get(requestURL); } + // eslint-disable-next-line default-param-last filter(page = 1, sortAttr = 'name', queryPayload) { let requestURL = `${this.url}/filter?${buildContactParams(page, sortAttr)}`; return axios.post(requestURL, queryPayload); diff --git a/app/javascript/dashboard/api/enterprise/specs/account.spec.js b/app/javascript/dashboard/api/enterprise/specs/account.spec.js index 28fd83cd1..6c9dca986 100644 --- a/app/javascript/dashboard/api/enterprise/specs/account.spec.js +++ b/app/javascript/dashboard/api/enterprise/specs/account.spec.js @@ -1,6 +1,5 @@ import accountAPI from '../account'; import ApiClient from '../../ApiClient'; -import describeWithAPIMock from '../../specs/apiSpecHelper'; describe('#enterpriseAccountAPI', () => { it('creates correct instance', () => { @@ -13,17 +12,33 @@ describe('#enterpriseAccountAPI', () => { expect(accountAPI).toHaveProperty('checkout'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#checkout', () => { accountAPI.checkout(); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/enterprise/api/v1/checkout' ); }); it('#subscription', () => { accountAPI.subscription(); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/enterprise/api/v1/subscription' ); }); diff --git a/app/javascript/dashboard/api/reports.js b/app/javascript/dashboard/api/reports.js index 7bc07b565..987b69701 100644 --- a/app/javascript/dashboard/api/reports.js +++ b/app/javascript/dashboard/api/reports.js @@ -31,6 +31,7 @@ class ReportsAPI extends ApiClient { }); } + // eslint-disable-next-line default-param-last getSummary(since, until, type = 'account', id, groupBy, businessHours) { return axios.get(`${this.url}/summary`, { params: { diff --git a/app/javascript/dashboard/api/specs/account.spec.js b/app/javascript/dashboard/api/specs/account.spec.js index 3d37c4206..7e213b2a8 100644 --- a/app/javascript/dashboard/api/specs/account.spec.js +++ b/app/javascript/dashboard/api/specs/account.spec.js @@ -1,6 +1,5 @@ import accountAPI from '../account'; import ApiClient from '../ApiClient'; -import describeWithAPIMock from './apiSpecHelper'; describe('#accountAPI', () => { it('creates correct instance', () => { @@ -13,12 +12,28 @@ describe('#accountAPI', () => { expect(accountAPI).toHaveProperty('createAccount'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#createAccount', () => { accountAPI.createAccount({ name: 'Chatwoot', }); - expect(context.axiosMock.post).toHaveBeenCalledWith('/api/v1/accounts', { + expect(axiosMock.post).toHaveBeenCalledWith('/api/v1/accounts', { name: 'Chatwoot', }); }); diff --git a/app/javascript/dashboard/api/specs/accountActions.spec.js b/app/javascript/dashboard/api/specs/accountActions.spec.js index 45f9663f3..330c117ff 100644 --- a/app/javascript/dashboard/api/specs/accountActions.spec.js +++ b/app/javascript/dashboard/api/specs/accountActions.spec.js @@ -1,6 +1,5 @@ import accountActionsAPI from '../accountActions'; import ApiClient from '../ApiClient'; -import describeWithAPIMock from './apiSpecHelper'; describe('#ContactsAPI', () => { it('creates correct instance', () => { @@ -8,10 +7,26 @@ describe('#ContactsAPI', () => { expect(accountActionsAPI).toHaveProperty('merge'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#merge', () => { accountActionsAPI.merge(1, 2); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/actions/contact_merge', { base_contact_id: 1, diff --git a/app/javascript/dashboard/api/specs/apiSpecHelper.js b/app/javascript/dashboard/api/specs/apiSpecHelper.js deleted file mode 100644 index aab90b045..000000000 --- a/app/javascript/dashboard/api/specs/apiSpecHelper.js +++ /dev/null @@ -1,27 +0,0 @@ -function apiSpecHelper() { - beforeEach(() => { - this.originalAxios = window.axios; - this.axiosMock = { - post: jest.fn(() => Promise.resolve()), - get: jest.fn(() => Promise.resolve()), - patch: jest.fn(() => Promise.resolve()), - delete: jest.fn(() => Promise.resolve()), - }; - window.axios = this.axiosMock; - }); - - afterEach(() => { - window.axios = this.originalAxios; - }); -} -// https://stackoverflow.com/a/59344023/3901856 -const sharedWrapper = describe('sharedWrapper', () => {}); -export default function describeWithAPIMock(skillName, testFn) { - return describe(skillName, function configureContext() { - function Context() {} - Context.prototype = sharedWrapper.ctx; - this.ctx = new Context(); - apiSpecHelper.call(this); - testFn.call(this, this); - }); -} diff --git a/app/javascript/dashboard/api/specs/article.spec.js b/app/javascript/dashboard/api/specs/article.spec.js index 51e90318f..b8886b4f8 100644 --- a/app/javascript/dashboard/api/specs/article.spec.js +++ b/app/javascript/dashboard/api/specs/article.spec.js @@ -1,6 +1,5 @@ import articlesAPI from '../helpCenter/articles'; import ApiClient from 'dashboard/api/helpCenter/portals'; -import describeWithAPIMock from './apiSpecHelper'; describe('#PortalAPI', () => { it('creates correct instance', () => { @@ -12,7 +11,23 @@ describe('#PortalAPI', () => { expect(articlesAPI).toHaveProperty('delete'); expect(articlesAPI).toHaveProperty('getArticles'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#getArticles', () => { articlesAPI.getArticles({ pageNumber: 1, @@ -21,30 +36,62 @@ describe('#PortalAPI', () => { status: 'published', author_id: '1', }); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/portals/room-rental/articles?page=1&locale=en-US&status=published&author_id=1' ); }); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#getArticle', () => { articlesAPI.getArticle({ id: 1, portalSlug: 'room-rental', }); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/portals/room-rental/articles/1' ); }); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#updateArticle', () => { articlesAPI.updateArticle({ articleId: 1, portalSlug: 'room-rental', articleObj: { title: 'Update shipping address' }, }); - expect(context.axiosMock.patch).toHaveBeenCalledWith( + expect(axiosMock.patch).toHaveBeenCalledWith( '/api/v1/portals/room-rental/articles/1', { title: 'Update shipping address', @@ -52,13 +99,29 @@ describe('#PortalAPI', () => { ); }); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#deleteArticle', () => { articlesAPI.deleteArticle({ articleId: 1, portalSlug: 'room-rental', }); - expect(context.axiosMock.delete).toHaveBeenCalledWith( + expect(axiosMock.delete).toHaveBeenCalledWith( '/api/v1/portals/room-rental/articles/1' ); }); diff --git a/app/javascript/dashboard/api/specs/assignableAgents.spec.js b/app/javascript/dashboard/api/specs/assignableAgents.spec.js index 6c9c5ec9a..5280162b3 100644 --- a/app/javascript/dashboard/api/specs/assignableAgents.spec.js +++ b/app/javascript/dashboard/api/specs/assignableAgents.spec.js @@ -1,18 +1,30 @@ import assignableAgentsAPI from '../assignableAgents'; -import describeWithAPIMock from './apiSpecHelper'; describe('#AssignableAgentsAPI', () => { - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#getAssignableAgents', () => { assignableAgentsAPI.get([1]); - expect(context.axiosMock.get).toHaveBeenCalledWith( - '/api/v1/assignable_agents', - { - params: { - inbox_ids: [1], - }, - } - ); + expect(axiosMock.get).toHaveBeenCalledWith('/api/v1/assignable_agents', { + params: { + inbox_ids: [1], + }, + }); }); }); }); diff --git a/app/javascript/dashboard/api/specs/channel/fbChannel.spec.js b/app/javascript/dashboard/api/specs/channel/fbChannel.spec.js index 67697f827..2cdcec56e 100644 --- a/app/javascript/dashboard/api/specs/channel/fbChannel.spec.js +++ b/app/javascript/dashboard/api/specs/channel/fbChannel.spec.js @@ -1,6 +1,5 @@ import fbChannel from '../../channel/fbChannel'; import ApiClient from '../../ApiClient'; -import describeWithAPIMock from '../apiSpecHelper'; describe('#FBChannel', () => { it('creates correct instance', () => { @@ -11,10 +10,26 @@ describe('#FBChannel', () => { expect(fbChannel).toHaveProperty('update'); expect(fbChannel).toHaveProperty('delete'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#create', () => { fbChannel.create({ omniauthToken: 'ASFM131CSF@#@$', appId: 'chatwoot' }); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/callbacks/register_facebook_page', { omniauthToken: 'ASFM131CSF@#@$', @@ -27,7 +42,7 @@ describe('#FBChannel', () => { omniauthToken: 'ASFM131CSF@#@$', inboxId: 1, }); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/callbacks/reauthorize_page', { omniauth_token: 'ASFM131CSF@#@$', diff --git a/app/javascript/dashboard/api/specs/contacts.spec.js b/app/javascript/dashboard/api/specs/contacts.spec.js index dc034480a..b4eaf7333 100644 --- a/app/javascript/dashboard/api/specs/contacts.spec.js +++ b/app/javascript/dashboard/api/specs/contacts.spec.js @@ -1,6 +1,5 @@ import contactAPI, { buildContactParams } from '../contacts'; import ApiClient from '../ApiClient'; -import describeWithAPIMock from './apiSpecHelper'; describe('#ContactsAPI', () => { it('creates correct instance', () => { @@ -15,56 +14,67 @@ describe('#ContactsAPI', () => { expect(contactAPI).toHaveProperty('destroyAvatar'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#get', () => { contactAPI.get(1, 'name', 'customer-support'); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/contacts?include_contact_inboxes=false&page=1&sort=name&labels[]=customer-support' ); }); it('#getConversations', () => { contactAPI.getConversations(1); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/contacts/1/conversations' ); }); it('#getContactableInboxes', () => { contactAPI.getContactableInboxes(1); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/contacts/1/contactable_inboxes' ); }); it('#getContactLabels', () => { contactAPI.getContactLabels(1); - expect(context.axiosMock.get).toHaveBeenCalledWith( - '/api/v1/contacts/1/labels' - ); + expect(axiosMock.get).toHaveBeenCalledWith('/api/v1/contacts/1/labels'); }); it('#updateContactLabels', () => { const labels = ['support-query']; contactAPI.updateContactLabels(1, labels); - expect(context.axiosMock.post).toHaveBeenCalledWith( - '/api/v1/contacts/1/labels', - { - labels, - } - ); + expect(axiosMock.post).toHaveBeenCalledWith('/api/v1/contacts/1/labels', { + labels, + }); }); it('#search', () => { contactAPI.search('leads', 1, 'date', 'customer-support'); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/contacts/search?include_contact_inboxes=false&page=1&sort=date&q=leads&labels[]=customer-support' ); }); it('#destroyCustomAttributes', () => { contactAPI.destroyCustomAttributes(1, ['cloudCustomer']); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/contacts/1/destroy_custom_attributes', { custom_attributes: ['cloudCustomer'], @@ -75,7 +85,7 @@ describe('#ContactsAPI', () => { it('#importContacts', () => { const file = 'file'; contactAPI.importContacts(file); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/contacts/import', expect.any(FormData), { @@ -96,7 +106,7 @@ describe('#ContactsAPI', () => { ], }; contactAPI.filter(1, 'name', queryPayload); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/contacts/filter?include_contact_inboxes=false&page=1&sort=name', queryPayload ); @@ -104,7 +114,7 @@ describe('#ContactsAPI', () => { it('#destroyAvatar', () => { contactAPI.destroyAvatar(1); - expect(context.axiosMock.delete).toHaveBeenCalledWith( + expect(axiosMock.delete).toHaveBeenCalledWith( '/api/v1/contacts/1/avatar' ); }); diff --git a/app/javascript/dashboard/api/specs/conversations.spec.js b/app/javascript/dashboard/api/specs/conversations.spec.js index 4b1a0a030..6b3db7404 100644 --- a/app/javascript/dashboard/api/specs/conversations.spec.js +++ b/app/javascript/dashboard/api/specs/conversations.spec.js @@ -1,6 +1,5 @@ import conversationsAPI from '../conversations'; import ApiClient from '../ApiClient'; -import describeWithAPIMock from './apiSpecHelper'; describe('#ConversationApi', () => { it('creates correct instance', () => { @@ -14,10 +13,26 @@ describe('#ConversationApi', () => { expect(conversationsAPI).toHaveProperty('updateLabels'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#getLabels', () => { conversationsAPI.getLabels(1); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/conversations/1/labels' ); }); @@ -25,7 +40,7 @@ describe('#ConversationApi', () => { it('#updateLabels', () => { const labels = ['support-query']; conversationsAPI.updateLabels(1, labels); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/conversations/1/labels', { labels, diff --git a/app/javascript/dashboard/api/specs/csatReports.spec.js b/app/javascript/dashboard/api/specs/csatReports.spec.js index a1d6e50f2..7c1707e1e 100644 --- a/app/javascript/dashboard/api/specs/csatReports.spec.js +++ b/app/javascript/dashboard/api/specs/csatReports.spec.js @@ -1,6 +1,5 @@ import csatReportsAPI from '../csatReports'; import ApiClient from '../ApiClient'; -import describeWithAPIMock from './apiSpecHelper'; describe('#Reports API', () => { it('creates correct instance', () => { @@ -9,10 +8,26 @@ describe('#Reports API', () => { expect(csatReportsAPI).toHaveProperty('get'); expect(csatReportsAPI).toHaveProperty('getMetrics'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#get', () => { csatReportsAPI.get({ page: 1, from: 1622485800, to: 1623695400 }); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/csat_survey_responses', { params: { @@ -26,7 +41,7 @@ describe('#Reports API', () => { }); it('#getMetrics', () => { csatReportsAPI.getMetrics({ from: 1622485800, to: 1623695400 }); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/csat_survey_responses/metrics', { params: { since: 1622485800, until: 1623695400 }, @@ -39,7 +54,7 @@ describe('#Reports API', () => { to: 1623695400, user_ids: 1, }); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/csat_survey_responses/download', { params: { diff --git a/app/javascript/dashboard/api/specs/inbox/conversation.spec.js b/app/javascript/dashboard/api/specs/inbox/conversation.spec.js index 08343b69c..ecc833e16 100644 --- a/app/javascript/dashboard/api/specs/inbox/conversation.spec.js +++ b/app/javascript/dashboard/api/specs/inbox/conversation.spec.js @@ -1,6 +1,5 @@ import conversationAPI from '../../inbox/conversation'; import ApiClient from '../../ApiClient'; -import describeWithAPIMock from '../apiSpecHelper'; describe('#ConversationAPI', () => { it('creates correct instance', () => { @@ -22,7 +21,23 @@ describe('#ConversationAPI', () => { expect(conversationAPI).toHaveProperty('filter'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#get conversations', () => { conversationAPI.get({ inboxId: 1, @@ -32,19 +47,16 @@ describe('#ConversationAPI', () => { labels: [], teamId: 1, }); - expect(context.axiosMock.get).toHaveBeenCalledWith( - '/api/v1/conversations', - { - params: { - inbox_id: 1, - team_id: 1, - status: 'open', - assignee_type: 'me', - page: 1, - labels: [], - }, - } - ); + expect(axiosMock.get).toHaveBeenCalledWith('/api/v1/conversations', { + params: { + inbox_id: 1, + team_id: 1, + status: 'open', + assignee_type: 'me', + page: 1, + labels: [], + }, + }); }); it('#search', () => { @@ -53,7 +65,7 @@ describe('#ConversationAPI', () => { page: 1, }); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/conversations/search', { params: { @@ -66,7 +78,7 @@ describe('#ConversationAPI', () => { it('#toggleStatus', () => { conversationAPI.toggleStatus({ conversationId: 12, status: 'online' }); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( `/api/v1/conversations/12/toggle_status`, { status: 'online', @@ -77,7 +89,7 @@ describe('#ConversationAPI', () => { it('#assignAgent', () => { conversationAPI.assignAgent({ conversationId: 12, agentId: 34 }); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( `/api/v1/conversations/12/assignments?assignee_id=34`, {} ); @@ -85,7 +97,7 @@ describe('#ConversationAPI', () => { it('#assignTeam', () => { conversationAPI.assignTeam({ conversationId: 12, teamId: 1 }); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( `/api/v1/conversations/12/assignments`, { team_id: 1, @@ -95,7 +107,7 @@ describe('#ConversationAPI', () => { it('#markMessageRead', () => { conversationAPI.markMessageRead({ id: 12 }); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( `/api/v1/conversations/12/update_last_seen` ); }); @@ -105,7 +117,7 @@ describe('#ConversationAPI', () => { conversationId: 12, status: 'typing_on', }); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( `/api/v1/conversations/12/toggle_typing_status`, { typing_status: 'typing_on', @@ -115,14 +127,14 @@ describe('#ConversationAPI', () => { it('#mute', () => { conversationAPI.mute(45); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/conversations/45/mute' ); }); it('#unmute', () => { conversationAPI.unmute(45); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/conversations/45/unmute' ); }); @@ -135,18 +147,15 @@ describe('#ConversationAPI', () => { labels: [], teamId: 1, }); - expect(context.axiosMock.get).toHaveBeenCalledWith( - '/api/v1/conversations/meta', - { - params: { - inbox_id: 1, - team_id: 1, - status: 'open', - assignee_type: 'me', - labels: [], - }, - } - ); + expect(axiosMock.get).toHaveBeenCalledWith('/api/v1/conversations/meta', { + params: { + inbox_id: 1, + team_id: 1, + status: 'open', + assignee_type: 'me', + labels: [], + }, + }); }); it('#sendEmailTranscript', () => { @@ -154,7 +163,7 @@ describe('#ConversationAPI', () => { conversationId: 45, email: 'john@acme.inc', }); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/conversations/45/transcript', { email: 'john@acme.inc', @@ -167,7 +176,7 @@ describe('#ConversationAPI', () => { conversationId: 45, customAttributes: { order_d: '1001' }, }); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/conversations/45/custom_attributes', { custom_attributes: { order_d: '1001' }, @@ -202,9 +211,7 @@ describe('#ConversationAPI', () => { }, }; conversationAPI.filter(payload); - expect( - context.axiosMock.post - ).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/conversations/filter', payload.queryData, { params: { page: payload.page } } @@ -213,7 +220,7 @@ describe('#ConversationAPI', () => { it('#getAllAttachments', () => { conversationAPI.getAllAttachments(1); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/conversations/1/attachments' ); }); diff --git a/app/javascript/dashboard/api/specs/inbox/message.spec.js b/app/javascript/dashboard/api/specs/inbox/message.spec.js index 6953621cb..e75bf34b0 100644 --- a/app/javascript/dashboard/api/specs/inbox/message.spec.js +++ b/app/javascript/dashboard/api/specs/inbox/message.spec.js @@ -1,6 +1,5 @@ import messageAPI, { buildCreatePayload } from '../../inbox/message'; import ApiClient from '../../ApiClient'; -import describeWithAPIMock from '../apiSpecHelper'; describe('#ConversationAPI', () => { it('creates correct instance', () => { @@ -13,13 +12,29 @@ describe('#ConversationAPI', () => { expect(messageAPI).toHaveProperty('getPreviousMessages'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#getPreviousMessages', () => { messageAPI.getPreviousMessages({ conversationId: 12, before: 4573, }); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( `/api/v1/conversations/12/messages`, { params: { @@ -35,7 +50,6 @@ describe('#ConversationAPI', () => { message: 'test content', echoId: 12, isPrivate: true, - files: [new Blob(['test-content'], { type: 'application/pdf' })], }); expect(formPayload).toBeInstanceOf(FormData); @@ -58,8 +72,10 @@ describe('#ConversationAPI', () => { private: false, echo_id: 12, content_attributes: { in_reply_to: 12 }, - bcc_emails: '', cc_emails: '', + bcc_emails: '', + to_emails: '', + template_params: undefined, }); }); }); diff --git a/app/javascript/dashboard/api/specs/inboxes.spec.js b/app/javascript/dashboard/api/specs/inboxes.spec.js index e471dac86..8834ceb07 100644 --- a/app/javascript/dashboard/api/specs/inboxes.spec.js +++ b/app/javascript/dashboard/api/specs/inboxes.spec.js @@ -1,6 +1,5 @@ import inboxesAPI from '../inboxes'; import ApiClient from '../ApiClient'; -import describeWithAPIMock from './apiSpecHelper'; describe('#InboxesAPI', () => { it('creates correct instance', () => { @@ -14,19 +13,32 @@ describe('#InboxesAPI', () => { expect(inboxesAPI).toHaveProperty('getAgentBot'); expect(inboxesAPI).toHaveProperty('setAgentBot'); }); - describeWithAPIMock('API calls', context => { + + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#getCampaigns', () => { inboxesAPI.getCampaigns(2); - expect(context.axiosMock.get).toHaveBeenCalledWith( - '/api/v1/inboxes/2/campaigns' - ); + expect(axiosMock.get).toHaveBeenCalledWith('/api/v1/inboxes/2/campaigns'); }); it('#deleteInboxAvatar', () => { inboxesAPI.deleteInboxAvatar(2); - expect(context.axiosMock.delete).toHaveBeenCalledWith( - '/api/v1/inboxes/2/avatar' - ); + expect(axiosMock.delete).toHaveBeenCalledWith('/api/v1/inboxes/2/avatar'); }); }); }); diff --git a/app/javascript/dashboard/api/specs/integrations.spec.js b/app/javascript/dashboard/api/specs/integrations.spec.js index 890cc7c84..5ccbda436 100644 --- a/app/javascript/dashboard/api/specs/integrations.spec.js +++ b/app/javascript/dashboard/api/specs/integrations.spec.js @@ -1,6 +1,5 @@ import integrationAPI from '../integrations'; import ApiClient from '../ApiClient'; -import describeWithAPIMock from './apiSpecHelper'; describe('#integrationAPI', () => { it('creates correct instance', () => { @@ -16,11 +15,27 @@ describe('#integrationAPI', () => { expect(integrationAPI).toHaveProperty('listAllSlackChannels'); expect(integrationAPI).toHaveProperty('deleteHook'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#connectSlack', () => { const code = 'SDNFJNSDFNDSJN'; integrationAPI.connectSlack(code); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/integrations/slack', { code, @@ -31,7 +46,7 @@ describe('#integrationAPI', () => { it('#updateSlack', () => { const updateObj = { referenceId: 'SDFSDGSVE' }; integrationAPI.updateSlack(updateObj); - expect(context.axiosMock.patch).toHaveBeenCalledWith( + expect(axiosMock.patch).toHaveBeenCalledWith( '/api/v1/integrations/slack', { reference_id: updateObj.referenceId, @@ -41,16 +56,14 @@ describe('#integrationAPI', () => { it('#listAllSlackChannels', () => { integrationAPI.listAllSlackChannels(); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/integrations/slack/list_all_channels' ); }); it('#delete', () => { integrationAPI.delete(2); - expect(context.axiosMock.delete).toHaveBeenCalledWith( - '/api/v1/integrations/2' - ); + expect(axiosMock.delete).toHaveBeenCalledWith('/api/v1/integrations/2'); }); it('#createHook', () => { @@ -59,7 +72,7 @@ describe('#integrationAPI', () => { settings: { api_key: 'SDFSDGSVE' }, }; integrationAPI.createHook(hookData); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/integrations/hooks', hookData ); @@ -67,7 +80,7 @@ describe('#integrationAPI', () => { it('#deleteHook', () => { integrationAPI.deleteHook(2); - expect(context.axiosMock.delete).toHaveBeenCalledWith( + expect(axiosMock.delete).toHaveBeenCalledWith( '/api/v1/integrations/hooks/2' ); }); diff --git a/app/javascript/dashboard/api/specs/integrations/dyte.spec.js b/app/javascript/dashboard/api/specs/integrations/dyte.spec.js index c89c2106e..4bbe0484a 100644 --- a/app/javascript/dashboard/api/specs/integrations/dyte.spec.js +++ b/app/javascript/dashboard/api/specs/integrations/dyte.spec.js @@ -1,6 +1,5 @@ import DyteAPIClient from '../../integrations/dyte'; import ApiClient from '../../ApiClient'; -import describeWithAPIMock from '../apiSpecHelper'; describe('#accountAPI', () => { it('creates correct instance', () => { @@ -9,10 +8,26 @@ describe('#accountAPI', () => { expect(DyteAPIClient).toHaveProperty('addParticipantToMeeting'); }); - describeWithAPIMock('createAMeeting', context => { + describe('createAMeeting', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('creates a valid request', () => { DyteAPIClient.createAMeeting(1); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/integrations/dyte/create_a_meeting', { conversation_id: 1, @@ -21,10 +36,26 @@ describe('#accountAPI', () => { }); }); - describeWithAPIMock('addParticipantToMeeting', context => { + describe('addParticipantToMeeting', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('creates a valid request', () => { DyteAPIClient.addParticipantToMeeting(1); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/integrations/dyte/add_participant_to_meeting', { message_id: 1, diff --git a/app/javascript/dashboard/api/specs/notifications.spec.js b/app/javascript/dashboard/api/specs/notifications.spec.js index d20c0d526..5bdf88d7f 100644 --- a/app/javascript/dashboard/api/specs/notifications.spec.js +++ b/app/javascript/dashboard/api/specs/notifications.spec.js @@ -1,6 +1,5 @@ import notificationsAPI from '../notifications'; import ApiClient from '../ApiClient'; -import describeWithAPIMock from './apiSpecHelper'; describe('#NotificationAPI', () => { it('creates correct instance', () => { @@ -11,31 +10,47 @@ describe('#NotificationAPI', () => { expect(notificationsAPI).toHaveProperty('read'); expect(notificationsAPI).toHaveProperty('readAll'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#get', () => { notificationsAPI.get(1); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/notifications?page=1' ); }); it('#getNotifications', () => { notificationsAPI.getNotifications(1); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/notifications/1/notifications' ); }); it('#getUnreadCount', () => { notificationsAPI.getUnreadCount(); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/notifications/unread_count' ); }); it('#read', () => { notificationsAPI.read(48670, 'Conversation'); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/notifications/read_all', { primary_actor_id: 'Conversation', @@ -46,7 +61,7 @@ describe('#NotificationAPI', () => { it('#readAll', () => { notificationsAPI.readAll(); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/notifications/read_all' ); }); diff --git a/app/javascript/dashboard/api/specs/reports.spec.js b/app/javascript/dashboard/api/specs/reports.spec.js index 368997859..7822dad8f 100644 --- a/app/javascript/dashboard/api/specs/reports.spec.js +++ b/app/javascript/dashboard/api/specs/reports.spec.js @@ -1,6 +1,5 @@ import reportsAPI from '../reports'; import ApiClient from '../ApiClient'; -import describeWithAPIMock from './apiSpecHelper'; describe('#Reports API', () => { it('creates correct instance', () => { @@ -18,14 +17,30 @@ describe('#Reports API', () => { expect(reportsAPI).toHaveProperty('getInboxReports'); expect(reportsAPI).toHaveProperty('getTeamReports'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#getAccountReports', () => { reportsAPI.getReports({ metric: 'conversations_count', from: 1621103400, to: 1621621800, }); - expect(context.axiosMock.get).toHaveBeenCalledWith('/api/v2/reports', { + expect(axiosMock.get).toHaveBeenCalledWith('/api/v2/reports', { params: { metric: 'conversations_count', since: 1621103400, @@ -38,20 +53,17 @@ describe('#Reports API', () => { it('#getAccountSummary', () => { reportsAPI.getSummary(1621103400, 1621621800); - expect(context.axiosMock.get).toHaveBeenCalledWith( - '/api/v2/reports/summary', - { - params: { - business_hours: undefined, - group_by: undefined, - id: undefined, - since: 1621103400, - timezone_offset: -0, - type: 'account', - until: 1621621800, - }, - } - ); + expect(axiosMock.get).toHaveBeenCalledWith('/api/v2/reports/summary', { + params: { + business_hours: undefined, + group_by: undefined, + id: undefined, + since: 1621103400, + timezone_offset: -0, + type: 'account', + until: 1621621800, + }, + }); }); it('#getAgentReports', () => { @@ -60,60 +72,48 @@ describe('#Reports API', () => { to: 1621621800, businessHours: true, }); - expect(context.axiosMock.get).toHaveBeenCalledWith( - '/api/v2/reports/agents', - { - params: { - since: 1621103400, - until: 1621621800, - business_hours: true, - }, - } - ); + expect(axiosMock.get).toHaveBeenCalledWith('/api/v2/reports/agents', { + params: { + since: 1621103400, + until: 1621621800, + business_hours: true, + }, + }); }); it('#getLabelReports', () => { reportsAPI.getLabelReports({ from: 1621103400, to: 1621621800 }); - expect(context.axiosMock.get).toHaveBeenCalledWith( - '/api/v2/reports/labels', - { - params: { - since: 1621103400, - until: 1621621800, - }, - } - ); + expect(axiosMock.get).toHaveBeenCalledWith('/api/v2/reports/labels', { + params: { + since: 1621103400, + until: 1621621800, + }, + }); }); it('#getInboxReports', () => { reportsAPI.getInboxReports({ from: 1621103400, to: 1621621800 }); - expect(context.axiosMock.get).toHaveBeenCalledWith( - '/api/v2/reports/inboxes', - { - params: { - since: 1621103400, - until: 1621621800, - }, - } - ); + expect(axiosMock.get).toHaveBeenCalledWith('/api/v2/reports/inboxes', { + params: { + since: 1621103400, + until: 1621621800, + }, + }); }); it('#getTeamReports', () => { reportsAPI.getTeamReports({ from: 1621103400, to: 1621621800 }); - expect(context.axiosMock.get).toHaveBeenCalledWith( - '/api/v2/reports/teams', - { - params: { - since: 1621103400, - until: 1621621800, - }, - } - ); + expect(axiosMock.get).toHaveBeenCalledWith('/api/v2/reports/teams', { + params: { + since: 1621103400, + until: 1621621800, + }, + }); }); it('#getConversationMetric', () => { reportsAPI.getConversationMetric('account'); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v2/reports/conversations', { params: { diff --git a/app/javascript/dashboard/api/specs/teams.spec.js b/app/javascript/dashboard/api/specs/teams.spec.js index 4f29af554..3a59f2c51 100644 --- a/app/javascript/dashboard/api/specs/teams.spec.js +++ b/app/javascript/dashboard/api/specs/teams.spec.js @@ -1,6 +1,5 @@ import teamsAPI from '../teams'; import ApiClient from '../ApiClient'; -import describeWithAPIMock from './apiSpecHelper'; describe('#TeamsAPI', () => { it('creates correct instance', () => { @@ -14,17 +13,33 @@ describe('#TeamsAPI', () => { expect(teamsAPI).toHaveProperty('addAgents'); expect(teamsAPI).toHaveProperty('updateAgents'); }); - describeWithAPIMock('API calls', context => { + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + get: jest.fn(() => Promise.resolve()), + patch: jest.fn(() => Promise.resolve()), + delete: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + it('#getAgents', () => { teamsAPI.getAgents({ teamId: 1 }); - expect(context.axiosMock.get).toHaveBeenCalledWith( + expect(axiosMock.get).toHaveBeenCalledWith( '/api/v1/teams/1/team_members' ); }); it('#addAgents', () => { teamsAPI.addAgents({ teamId: 1, agentsList: { user_ids: [1, 10, 21] } }); - expect(context.axiosMock.post).toHaveBeenCalledWith( + expect(axiosMock.post).toHaveBeenCalledWith( '/api/v1/teams/1/team_members', { user_ids: { user_ids: [1, 10, 21] }, @@ -38,7 +53,7 @@ describe('#TeamsAPI', () => { teamId: 1, agentsList, }); - expect(context.axiosMock.patch).toHaveBeenCalledWith( + expect(axiosMock.patch).toHaveBeenCalledWith( '/api/v1/teams/1/team_members', { user_ids: agentsList, diff --git a/app/javascript/dashboard/components/ChatList.vue b/app/javascript/dashboard/components/ChatList.vue index e0b722ab3..b90ee30f6 100644 --- a/app/javascript/dashboard/components/ChatList.vue +++ b/app/javascript/dashboard/components/ChatList.vue @@ -10,7 +10,8 @@
@@ -24,9 +25,7 @@ v-if="!hasAppliedFiltersOrActiveFolders" class="p-1 my-0.5 mx-1 rounded-md capitalize bg-slate-50 dark:bg-slate-800 text-xxs text-slate-600 dark:text-slate-300" > - {{ - this.$t(`CHAT_LIST.CHAT_STATUS_FILTER_ITEMS.${activeStatus}.TEXT`) - }} + {{ $t(`CHAT_LIST.CHAT_STATUS_FILTER_ITEMS.${activeStatus}.TEXT`) }}
@@ -642,10 +641,8 @@ export default { }, handleKeyEvents(e) { if (hasPressedAltAndJKey(e)) { - const { - allConversations, - activeConversationIndex, - } = this.getKeyboardListenerParams(); + const { allConversations, activeConversationIndex } = + this.getKeyboardListenerParams(); if (activeConversationIndex === -1) { allConversations[0].click(); } diff --git a/app/javascript/dashboard/components/CustomSnoozeModal.vue b/app/javascript/dashboard/components/CustomSnoozeModal.vue index f204bac9f..65f943d41 100644 --- a/app/javascript/dashboard/components/CustomSnoozeModal.vue +++ b/app/javascript/dashboard/components/CustomSnoozeModal.vue @@ -13,10 +13,10 @@ />
- {{ this.$t('CONVERSATION.CUSTOM_SNOOZE.CANCEL') }} + {{ $t('CONVERSATION.CUSTOM_SNOOZE.CANCEL') }} - {{ this.$t('CONVERSATION.CUSTOM_SNOOZE.APPLY') }} + {{ $t('CONVERSATION.CUSTOM_SNOOZE.APPLY') }}
diff --git a/app/javascript/dashboard/components/MaskedText.vue b/app/javascript/dashboard/components/MaskedText.vue index a3355ddfa..87531a07e 100644 --- a/app/javascript/dashboard/components/MaskedText.vue +++ b/app/javascript/dashboard/components/MaskedText.vue @@ -1,6 +1,6 @@