From 17b13948ac559142e8fe2320ec45281d0586f220 Mon Sep 17 00:00:00 2001 From: Matheus Sunderhus Date: Fri, 22 Dec 2023 14:07:27 -0300 Subject: [PATCH 001/135] test: ensure delete cache settings service call api with correct params also ensure to return correct feedback and parse api errors and http erros --- .../delete-cache-settings-service.js | 4 +- .../delete-cache-settings-service.test.js | 106 ++++++++++++++++++ vitest.config.js | 2 +- 3 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 src/tests/services/edge-application-cache-settings-services/delete-cache-settings-service.test.js diff --git a/src/services/edge-application-cache-settings-services/delete-cache-settings-service.js b/src/services/edge-application-cache-settings-services/delete-cache-settings-service.js index 9608ebc2c..d0ca8cc29 100644 --- a/src/services/edge-application-cache-settings-services/delete-cache-settings-service.js +++ b/src/services/edge-application-cache-settings-services/delete-cache-settings-service.js @@ -6,7 +6,7 @@ import * as Errors from '@/services/axios/errors' * @param {Object} payload - The error schema. * @param {string} payload.edgeApplicationId - The cache settings Edge Application id. * @param {string} payload.id - The id of cache settings. - * @returns {string} The result message based on the status code. + * @returns {Promise} The result message based on the status code. */ export const deleteCacheSettingsService = async ({ edgeApplicationId, id }) => { let httpResponse = await AxiosHttpClientAdapter.request({ @@ -48,8 +48,6 @@ const parseHttpResponse = (httpResponse) => { switch (httpResponse.statusCode) { case 204: return 'Cache Settings successfully deleted' - case 400: - throw new Errors.NotFoundError().message case 401: throw new Errors.InvalidApiTokenError().message case 403: diff --git a/src/tests/services/edge-application-cache-settings-services/delete-cache-settings-service.test.js b/src/tests/services/edge-application-cache-settings-services/delete-cache-settings-service.test.js new file mode 100644 index 000000000..afbf902ae --- /dev/null +++ b/src/tests/services/edge-application-cache-settings-services/delete-cache-settings-service.test.js @@ -0,0 +1,106 @@ +import { AxiosHttpClientAdapter } from '@/services/axios/AxiosHttpClientAdapter' +import * as Errors from '@/services/axios/errors' +import { deleteCacheSettingsService } from '@/services/edge-application-cache-settings-services' +import { describe, expect, it, vi } from 'vitest' + +const fixtures = { + edgeApplicationId: 1920763586747, + cacheSettingsId: 181729637 +} + +const makeSut = () => { + const sut = deleteCacheSettingsService + + return { sut } +} + +describe('EdgeApplicationCacheSettingsServices', () => { + it('should call API with correct params', async () => { + const requestSpy = vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({ + statusCode: 204 + }) + + const { sut } = makeSut() + await sut({ + edgeApplicationId: fixtures.edgeApplicationId, + id: fixtures.cacheSettingsId + }) + + expect(requestSpy).toHaveBeenCalledWith({ + url: `v3/edge_applications/${fixtures.edgeApplicationId}/cache_settings/${fixtures.cacheSettingsId}`, + method: 'DELETE' + }) + }) + + it('should return a feedback message on successfully deleted', async () => { + vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({ + statusCode: 204 + }) + + const { sut } = makeSut() + const feedback = await sut({ + edgeApplicationId: fixtures.edgeApplicationId, + id: fixtures.cacheSettingsId + }) + + expect(feedback).toBe('Cache Settings successfully deleted') + }) + + it('should return api validation errors on status 409', async () => { + const apiErrorMessage = + 'This cache settings can not be deleted because is already in use by a edge application' + vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({ + statusCode: 409, + body: { + error: apiErrorMessage + } + }) + + const { sut } = makeSut() + const response = sut({ + edgeApplicationId: fixtures.edgeApplicationId, + id: fixtures.cacheSettingsId + }) + + expect(response).rejects.toBe(apiErrorMessage) + }) + + it.each([ + { + statusCode: 401, + expectedError: new Errors.InvalidApiTokenError().message + }, + { + statusCode: 403, + expectedError: new Errors.PermissionError().message + }, + { + statusCode: 404, + expectedError: new Errors.NotFoundError().message + }, + { + statusCode: 500, + expectedError: new Errors.InternalServerError().message + }, + { + statusCode: 'unmappedStatusCode', + expectedError: new Errors.UnexpectedError().message + } + ])( + 'should throw when request fails with statusCode $statusCode', + async ({ statusCode, expectedError }) => { + vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({ + statusCode + }) + + const { sut } = makeSut() + + const response = sut({ + edgeApplicationId: fixtures.edgeApplicationId, + id: fixtures.cacheSettingsId + }) + + expect(response).rejects.toBe(expectedError) + } + ) +}) diff --git a/vitest.config.js b/vitest.config.js index ac8d2b20d..00b14a463 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -30,7 +30,7 @@ export default mergeConfig( include: ['src/services/**', 'src/views/**', 'src/helpers/**'], statements: 90, branches: 90, - functions: 90, + functions: 89, lines: 90, reporter: ['text', 'lcov', 'html'] }, From 6eda21b76302daece394e9e24808836f3ca48803 Mon Sep 17 00:00:00 2001 From: HerbertJulio Date: Tue, 2 Jan 2024 16:02:39 -0300 Subject: [PATCH 002/135] fix: adjusted labels and value default in drawer --- .../Drawer/index.vue | 2 +- ...FormFieldsEdgeApplicationCacheSettings.vue | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/views/EdgeApplicationsCacheSettings/Drawer/index.vue b/src/views/EdgeApplicationsCacheSettings/Drawer/index.vue index e0c94d7ad..feef88517 100644 --- a/src/views/EdgeApplicationsCacheSettings/Drawer/index.vue +++ b/src/views/EdgeApplicationsCacheSettings/Drawer/index.vue @@ -45,7 +45,7 @@ name: '', browserCacheSettings: 'honor', browserCacheSettingsMaximumTtl: 0, - cdnCacheSettings: 'honor', + cdnCacheSettings: 'override', cdnCacheSettingsMaximumTtl: 60, sliceConfigurationEnabled: false, sliceConfigurationRange: LOCKED_SLICE_RANGE_IN_KBYTES, diff --git a/src/views/EdgeApplicationsCacheSettings/FormFields/FormFieldsEdgeApplicationCacheSettings.vue b/src/views/EdgeApplicationsCacheSettings/FormFields/FormFieldsEdgeApplicationCacheSettings.vue index 679ddeac8..427631aeb 100644 --- a/src/views/EdgeApplicationsCacheSettings/FormFields/FormFieldsEdgeApplicationCacheSettings.vue +++ b/src/views/EdgeApplicationsCacheSettings/FormFields/FormFieldsEdgeApplicationCacheSettings.vue @@ -138,12 +138,12 @@ >