From 1301bb460ffc3e8d179492a08dbdb3a67aa080f8 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Fri, 19 Feb 2021 17:27:37 -0300 Subject: [PATCH] 17319: Adds tests exposing the bug. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- .../common-resource-service.test.ts | 11 ++++--- .../common-service/common-service.test.ts | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 src/services/common-service/common-service.test.ts diff --git a/src/services/common-service/common-resource-service.test.ts b/src/services/common-service/common-resource-service.test.ts index 038c6943..d00412b8 100644 --- a/src/services/common-service/common-resource-service.test.ts +++ b/src/services/common-service/common-resource-service.test.ts @@ -15,12 +15,11 @@ const actions: ApiActions = { export const mockResourceService = >( Service: new (client: AxiosInstance, actions: ApiActions) => C) => { - const axiosInstance = axios.create(); - const axiosMock = new MockAdapter(axiosInstance); - const service = new Service(axiosInstance, actions); - Object.keys(service).map(key => service[key] = jest.fn()); - return service; -}; + const axiosInstance = axios.create(); + const service = new Service(axiosInstance, actions); + Object.keys(service).map(key => service[key] = jest.fn()); + return service; + }; describe("CommonResourceService", () => { let axiosInstance: AxiosInstance; diff --git a/src/services/common-service/common-service.test.ts b/src/services/common-service/common-service.test.ts new file mode 100644 index 00000000..db36570a --- /dev/null +++ b/src/services/common-service/common-service.test.ts @@ -0,0 +1,30 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import axios from "axios"; +import { ApiActions } from "~/services/api/api-actions"; +import { CommonService } from "./common-service"; + +const actions: ApiActions = { + progressFn: (id: string, working: boolean) => {}, + errorFn: (id: string, message: string) => {} +}; + +describe("CommonService", () => { + const axiosInstance = axios.create(); + // const axiosMock = new MockAdapter(axiosInstance); + const commonService = new CommonService(axiosInstance, "resource", actions); + + it("throws an exception when passing uuid as empty string to get()", () => { + expect(() => commonService.get("")).toThrowError("UUID cannot be empty string"); + }); + + it("throws an exception when passing uuid as empty string to update()", () => { + expect(() => commonService.update("", {})).toThrowError("UUID cannot be empty string"); + }); + + it("throws an exception when passing uuid as empty string to delete()", () => { + expect(() => commonService.delete("")).toThrowError("UUID cannot be empty string"); + }); +}); \ No newline at end of file -- 2.30.2