diff --git a/components/alert/AlertAddAnalysis.vue b/components/alert/AlertAddAnalysis.vue index ca2a865..7374d03 100644 --- a/components/alert/AlertAddAnalysis.vue +++ b/components/alert/AlertAddAnalysis.vue @@ -85,7 +85,7 @@ const addFile = (event: Event) => { const uploadFile = async () => { if (!file.value) return; loading.value = true; - await $api.curService.uploadFile(file.value); + await $api.curApiClient.uploadFile(file.value); loading.value = false; emit("update:analyses"); closeModal(); diff --git a/components/comparative/ComparativeByRegion.vue b/components/comparative/ComparativeByRegion.vue index 4e72ddf..5f86d0d 100644 --- a/components/comparative/ComparativeByRegion.vue +++ b/components/comparative/ComparativeByRegion.vue @@ -63,7 +63,7 @@ interface Props { const props = defineProps(); const resultsByRegion: Ref = ref( - await $api.carbon.compareCarbonFootPrintbByRegion( + await $api.carbonService.compareCarbonFootPrintbByRegion( props.infrastructureId, props.totalCO2Gr, ), diff --git a/components/configurationSettings/ConfigurationSettingsInstanceType.vue b/components/configurationSettings/ConfigurationSettingsInstanceType.vue index bb39bc0..748ff8a 100644 --- a/components/configurationSettings/ConfigurationSettingsInstanceType.vue +++ b/components/configurationSettings/ConfigurationSettingsInstanceType.vue @@ -26,7 +26,7 @@ const { $api } = useNuxtApp(); const instanceTypes: Ref = ref([]); const isInstanceEmpty = ref(false); -$api.instanceType.getAllInstanceByType("EC2").then((responses) => { +$api.awsInstanceApiClient.getAllInstanceByType("EC2").then((responses) => { instanceTypes.value = responses.map((response) => response.name); }); diff --git a/components/infrastructure/InfrastructureCreate.vue b/components/infrastructure/InfrastructureCreate.vue index a78a795..fdd02be 100644 --- a/components/infrastructure/InfrastructureCreate.vue +++ b/components/infrastructure/InfrastructureCreate.vue @@ -120,7 +120,7 @@ const handleSubmit = form.handleSubmit(async (values) => { defaultRegion: values.region.id, name: values.infraName, }; - await $api.infrastructureService.createNewInfra(infra); + await $api.infrastructureApiClient.createNewInfra(infra); await infrastructuresStore.fetchInfrastructures(); isDialogOpen.value = false; emit("infraCreated"); diff --git a/components/infrastructure/InfrastructureDataTable.vue b/components/infrastructure/InfrastructureDataTable.vue index 7dce876..211a2dc 100644 --- a/components/infrastructure/InfrastructureDataTable.vue +++ b/components/infrastructure/InfrastructureDataTable.vue @@ -97,7 +97,7 @@ function deleteInfrastructure(infrastructure: Infrastructure) { } async function confirmInfrastructureDeletion(infrastructure: Infrastructure) { - await $api.infrastructureService.deleteInfra(infrastructure.id!); + await $api.infrastructureApiClient.deleteInfra(infrastructure.id!); await infrastructuresStore.fetchInfrastructures(); } diff --git a/pages/admin/dashboard.vue b/pages/admin/dashboard.vue index 7fd0310..ea76085 100644 --- a/pages/admin/dashboard.vue +++ b/pages/admin/dashboard.vue @@ -28,7 +28,7 @@ const notificationHandler = useToast(); const { $api } = useNuxtApp(); const clearCache = async () => { - await $api.adminService.evictRegionCache().then(() => + await $api.adminApiClient.evictRegionCache().then(() => notificationHandler.add({ title: $t("admin.regionCache.notifyCleared"), color: NuxtColors.success, diff --git a/pages/calculatrice/estimation/[infrastructureID]/index.vue b/pages/calculatrice/estimation/[infrastructureID]/index.vue index 5be351a..b270d1e 100644 --- a/pages/calculatrice/estimation/[infrastructureID]/index.vue +++ b/pages/calculatrice/estimation/[infrastructureID]/index.vue @@ -52,9 +52,9 @@ const infrastructureId: string = Array.isArray(route.params.infrastructureID) : route.params.infrastructureID; const results = ref( - await $api.carbon.estimateCarbonFootPrint(infrastructureId), + await $api.carbonService.estimateCarbonFootPrint(infrastructureId), ); infrastructure.value = - await $api.infrastructureService.getInfrastructure(infrastructureId); + await $api.infrastructureApiClient.getInfrastructure(infrastructureId); diff --git a/pages/calculatrice/infrastructure/[infrastructureID]/available-services.vue b/pages/calculatrice/infrastructure/[infrastructureID]/available-services.vue index a88028d..29ce62a 100644 --- a/pages/calculatrice/infrastructure/[infrastructureID]/available-services.vue +++ b/pages/calculatrice/infrastructure/[infrastructureID]/available-services.vue @@ -64,7 +64,7 @@ const route = useRoute(); const services = ref([]); services.value = - await $api.cloudServiceProviderService.getCloudServiceProviderServices(); + await $api.cloudServiceProviderApiClient.getCloudServiceProviderServices(); const goToComponentConfiguration = ( cloudServiceProviderService: CloudServiceProviderService, diff --git a/pages/calculatrice/infrastructure/[infrastructureID]/create-component.vue b/pages/calculatrice/infrastructure/[infrastructureID]/create-component.vue index 15108b9..63c814d 100644 --- a/pages/calculatrice/infrastructure/[infrastructureID]/create-component.vue +++ b/pages/calculatrice/infrastructure/[infrastructureID]/create-component.vue @@ -113,7 +113,9 @@ const { cloudServiceProviderServiceID, componentId, serviceName } = route.query as QueryParams; const components = ref( - await $api.componentService.getComponentsByInfrastructureId(infrastructureId), + await $api.componentApiClient.getComponentsByInfrastructureId( + infrastructureId, + ), ); const originalComponent = components.value.find( @@ -133,7 +135,7 @@ const isOtherRegion = ref( ); const serviceConfigurationSettings = ref( - await $api.serviceConfigurationSettingSvc.findAllConfigurationSettingsByServiceId( + await $api.serviceConfigurationSettingApiClient.findAllConfigurationSettingsByServiceId( originalComponent ? originalComponent.serviceID : cloudServiceProviderServiceID, @@ -171,12 +173,12 @@ const handleSubmit = async () => { serviceID: cloudServiceProviderServiceID, }; if (originalComponent) { - await $api.componentService.updateComponent({ + await $api.componentApiClient.updateComponent({ ...component, id: originalComponent.id, }); } else { - await $api.componentService.saveComponent(component); + await $api.componentApiClient.saveComponent(component); } await navigateTo(`/calculatrice/infrastructure/${infrastructureId}`); }; diff --git a/pages/calculatrice/infrastructure/[infrastructureID]/index.vue b/pages/calculatrice/infrastructure/[infrastructureID]/index.vue index 24432b0..98ab87d 100644 --- a/pages/calculatrice/infrastructure/[infrastructureID]/index.vue +++ b/pages/calculatrice/infrastructure/[infrastructureID]/index.vue @@ -116,7 +116,9 @@ const infrastructureId: string = Array.isArray(route.params.infrastructureID) const { $api } = useNuxtApp(); const components = ref( - await $api.componentService.getComponentsByInfrastructureId(infrastructureId), + await $api.componentApiClient.getComponentsByInfrastructureId( + infrastructureId, + ), ); const componentToDelete = ref(""); @@ -134,18 +136,18 @@ const addComponent = () => { }; async function deleteComponent() { - await useNuxtApp().$api.componentService.deleteComponent( + await useNuxtApp().$api.componentApiClient.deleteComponent( componentToDelete.value, ); components.value = - await $api.componentService.getComponentsByInfrastructureId( + await $api.componentApiClient.getComponentsByInfrastructureId( infrastructureId, ); } const navigateToEdit = async (component: Component) => { const { id: componentId, serviceID } = component; const serviceName = - (await $api.catalogService.getById(serviceID)).shortname ?? ""; + (await $api.catalogApiClient.getById(serviceID)).shortname ?? ""; navigateTo({ path: `/calculatrice/infrastructure/${infrastructureId}/create-component`, query: { diff --git a/pages/catalog/[serviceId]/index.vue b/pages/catalog/[serviceId]/index.vue index 3edac6a..418d619 100644 --- a/pages/catalog/[serviceId]/index.vue +++ b/pages/catalog/[serviceId]/index.vue @@ -39,7 +39,7 @@ const { const id: string = Array.isArray(serviceId) ? serviceId[0] : serviceId; const service: Ref = ref( - await $api.catalogService.getById(id), + await $api.catalogApiClient.getById(id), ); diff --git a/pages/catalog/index.vue b/pages/catalog/index.vue index 50a4298..c3759d7 100644 --- a/pages/catalog/index.vue +++ b/pages/catalog/index.vue @@ -24,11 +24,9 @@ definePageMeta({ layout: "public", }); -// const services: Ref = ref([]); - const { $api, $router } = useNuxtApp(); -const services = ref(await $api.catalogService.getAllServices()); +const services = ref(await $api.catalogApiClient.getAllServices()); const toDescription = (id: string) => { $router.push(`catalog/${id}`); diff --git a/plugins/02-irocalcApi.ts b/plugins/02-irocalcApi.ts index 075c51a..3fe8e24 100644 --- a/plugins/02-irocalcApi.ts +++ b/plugins/02-irocalcApi.ts @@ -19,32 +19,36 @@ import { createFetch } from "ofetch"; import { defineNuxtPlugin } from "#app"; import AWSDataCenterService from "../service/awsDataCenterService"; import CarbonService from "~/service/carbonService"; -import CatalogService from "~/service/catalogService"; -import AWSInstanceService from "~/service/awsInstanceService"; -import AdminService from "~/service/adminService"; +import CatalogApiClient from "~/service/api/catalogApiClient"; +import AWSInstanceApiClient from "~/service/api/AWSInstanceApiClient"; +import AdminApiClient from "~/service/api/adminApiClient"; import { useAuth } from "vue-clerk"; -import InfrastructureService from "~/service/infrastructureService"; -import CloudServiceProviderSvc from "~/service/CloudServiceProviderService"; -import ServiceConfigurationSettingSvc from "~/service/ServiceConfigurationSettingService"; -import ComponentService from "~/service/componentService"; +import InfrastructureApiClient from "~/service/api/infrastructureApiClient"; +import CloudServiceProviderApiClient from "~/service/api/CloudServiceProviderApiClient"; +import ServiceConfigurationSettingApiClient from "~/service/api/ServiceConfigurationSettingApiClient"; +import ComponentApiClient from "~/service/api/componentApiClient"; import AnalysisService from "~/service/analysisService"; -import CurService from "~/service/curService"; +import CurApiClient from "~/service/api/curApiClient"; import TokenService from "~/service/tokenService"; import ScanService from "~/service/scanService"; +import { AnalysisApiClient } from "~/service/api/analysisApiClient"; +import { AWSDataCenterApiClient } from "~/service/api/AWSDataCenterApiClient"; +import { IrocalcCarbonApiClient } from "~/service/api/irocalcCarbonApiClient"; +import ScanApiClient from "~/service/api/scanApiClient"; /** ApiInstance interface provides us with good typing */ interface IApiInstance { awsDataCenter: AWSDataCenterService; - carbon: CarbonService; - catalogService: CatalogService; - instanceType: AWSInstanceService; - adminService: AdminService; - infrastructureService: InfrastructureService; - componentService: ComponentService; - cloudServiceProviderService: CloudServiceProviderSvc; - serviceConfigurationSettingSvc: ServiceConfigurationSettingSvc; + carbonService: CarbonService; + catalogApiClient: CatalogApiClient; + awsInstanceApiClient: AWSInstanceApiClient; + adminApiClient: AdminApiClient; + infrastructureApiClient: InfrastructureApiClient; + componentApiClient: ComponentApiClient; + cloudServiceProviderApiClient: CloudServiceProviderApiClient; + serviceConfigurationSettingApiClient: ServiceConfigurationSettingApiClient; analysisService: AnalysisService; - curService: CurService; + curApiClient: CurApiClient; tokenService: TokenService; scanService: ScanService; } @@ -95,23 +99,29 @@ export default defineNuxtPlugin({ }, }); + const infrastructureApiClient = new InfrastructureApiClient(apiFetcher); + /** an object containing all repositories we need to expose */ const modules: IApiInstance = { - carbon: new CarbonService(apiFetcher), - awsDataCenter: new AWSDataCenterService(apiFetcher), - catalogService: new CatalogService(apiFetcher), - instanceType: new AWSInstanceService(apiFetcher), - adminService: new AdminService(apiFetcher), - infrastructureService: new InfrastructureService(apiFetcher), - componentService: new ComponentService(apiFetcher), - cloudServiceProviderService: new CloudServiceProviderSvc(apiFetcher), - serviceConfigurationSettingSvc: new ServiceConfigurationSettingSvc( + carbonService: new CarbonService(new IrocalcCarbonApiClient(apiFetcher)), + awsDataCenter: new AWSDataCenterService( + infrastructureApiClient, + new AWSDataCenterApiClient(apiFetcher), + ), + catalogApiClient: new CatalogApiClient(apiFetcher), + awsInstanceApiClient: new AWSInstanceApiClient(apiFetcher), + adminApiClient: new AdminApiClient(apiFetcher), + infrastructureApiClient: infrastructureApiClient, + componentApiClient: new ComponentApiClient(apiFetcher), + cloudServiceProviderApiClient: new CloudServiceProviderApiClient( apiFetcher, ), - analysisService: new AnalysisService(apiFetcher), - curService: new CurService(apiFetcher), + serviceConfigurationSettingApiClient: + new ServiceConfigurationSettingApiClient(apiFetcher), + analysisService: new AnalysisService(new AnalysisApiClient(apiFetcher)), + curApiClient: new CurApiClient(apiFetcher), tokenService: new TokenService(apiFetcher), - scanService: new ScanService(apiFetcher), + scanService: new ScanService(new ScanApiClient(apiFetcher)), }; return { diff --git a/service/analysisService.ts b/service/analysisService.ts index cda4c90..1838219 100644 --- a/service/analysisService.ts +++ b/service/analysisService.ts @@ -16,37 +16,39 @@ * SPDX-License-Identifier: Apache-2.0 */ -import HttpFactory from "./factory/httpFactory"; import type { ReportStatus } from "~/type/ReportStatus"; import type { Payload } from "~/type/Payload"; +import type { AnalysisApiClient } from "~/service/api/analysisApiClient"; -type Analysis = { +export type Analysis = { status: ReportStatus; id: string; dateCreation: string; co2Gr: number; }; -type AnalysisDetails = Analysis & { +export type AnalysisDetails = Analysis & { payloads: Payload[]; }; -class AnalysisService extends HttpFactory { - private readonly RESOURCE = "/api/analysis"; +class AnalysisService { + private readonly analysisApiClient: AnalysisApiClient; + + constructor(analysisApiClient: AnalysisApiClient) { + this.analysisApiClient = analysisApiClient; + } async getAllAnalyses() { - const analyses = await this.getCall(this.RESOURCE); - const analysesWithCO2Converted = analyses.map((analysis) => ({ + const analyses = await this.analysisApiClient.getAllAnalyses(); + return analyses.map((analysis) => ({ ...analysis, co2Converted: convertEstimateToBestMassUnit(analysis.co2Gr), })); - - return analysesWithCO2Converted; } async getAnalysisById(analysisId: string) { const estimated = ( - await this.getCall(`${this.RESOURCE}/${analysisId}`) + await this.analysisApiClient.getAnalysisById(analysisId) ).payloads.map((p) => ({ label: p.name, co2Gr: p.carbonGramFootprint, @@ -61,7 +63,7 @@ class AnalysisService extends HttpFactory { } async deleteAnalysis(analysisId: string): Promise { - return await this.deleteCall(`${this.RESOURCE}/${analysisId}`); + return await this.analysisApiClient.deleteAnalysis(analysisId); } } diff --git a/service/api/AWSDataCenterApiClient.ts b/service/api/AWSDataCenterApiClient.ts new file mode 100644 index 0000000..14379fc --- /dev/null +++ b/service/api/AWSDataCenterApiClient.ts @@ -0,0 +1,10 @@ +import ApiClient from "~/service/api/apiClient"; +import type { Region } from "~/type/Region"; + +export class AWSDataCenterApiClient extends ApiClient { + private readonly RESOURCE = "/api/cloud-service-providers"; + + async getAllAWSDataCenter(cspId: string): Promise { + return await this.getCall(`${this.RESOURCE}/${cspId}/regions`); + } +} diff --git a/service/awsInstanceService.ts b/service/api/AWSInstanceApiClient.ts similarity index 87% rename from service/awsInstanceService.ts rename to service/api/AWSInstanceApiClient.ts index 30841f8..4d4b5cc 100644 --- a/service/awsInstanceService.ts +++ b/service/api/AWSInstanceApiClient.ts @@ -15,10 +15,10 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import HttpFactory from "./factory/httpFactory"; +import ApiClient from "./apiClient"; import type { EC2InstanceType } from "~/type/ec2InstanceType"; -class AWSInstanceService extends HttpFactory { +class AWSInstanceApiClient extends ApiClient { private readonly RESOURCE = "/api/awsInstanceType"; async getAllInstanceByType( @@ -28,4 +28,4 @@ class AWSInstanceService extends HttpFactory { } } -export default AWSInstanceService; +export default AWSInstanceApiClient; diff --git a/service/CloudServiceProviderService.ts b/service/api/CloudServiceProviderApiClient.ts similarity index 90% rename from service/CloudServiceProviderService.ts rename to service/api/CloudServiceProviderApiClient.ts index b78ae00..b403e0d 100644 --- a/service/CloudServiceProviderService.ts +++ b/service/api/CloudServiceProviderApiClient.ts @@ -15,11 +15,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import HttpFactory from "./factory/httpFactory"; +import ApiClient from "./apiClient"; import type { CloudServiceProvider } from "~/type/infrastructure/CloudServiceProvider"; import type { CloudServiceProviderService } from "~/type/infrastructure/CloudServiceProviderService"; -class CloudServiceProviderSvc extends HttpFactory { +class CloudServiceProviderApiClient extends ApiClient { private readonly RESOURCE = "/api/cloud-service-providers"; async getCloudServiceProviders(): Promise { @@ -35,4 +35,4 @@ class CloudServiceProviderSvc extends HttpFactory { } } -export default CloudServiceProviderSvc; +export default CloudServiceProviderApiClient; diff --git a/service/ServiceConfigurationSettingService.ts b/service/api/ServiceConfigurationSettingApiClient.ts similarity index 87% rename from service/ServiceConfigurationSettingService.ts rename to service/api/ServiceConfigurationSettingApiClient.ts index 4104fe9..e36d69d 100644 --- a/service/ServiceConfigurationSettingService.ts +++ b/service/api/ServiceConfigurationSettingApiClient.ts @@ -15,10 +15,10 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import HttpFactory from "./factory/httpFactory"; +import ApiClient from "./apiClient"; import type { ServiceConfigurationSetting } from "~/type/infrastructure/ServiceConfigurationSetting"; -class ServiceConfigurationSettingSvc extends HttpFactory { +class ServiceConfigurationSettingApiClient extends ApiClient { private readonly RESOURCE = "/api/service-configuration-settings"; async findAllConfigurationSettingsByServiceId( @@ -30,4 +30,4 @@ class ServiceConfigurationSettingSvc extends HttpFactory { } } -export default ServiceConfigurationSettingSvc; +export default ServiceConfigurationSettingApiClient; diff --git a/service/adminService.ts b/service/api/adminApiClient.ts similarity index 86% rename from service/adminService.ts rename to service/api/adminApiClient.ts index 8e9ea2e..9792772 100644 --- a/service/adminService.ts +++ b/service/api/adminApiClient.ts @@ -15,12 +15,12 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import HttpFactory from "./factory/httpFactory"; +import ApiClient from "./apiClient"; -class AdminService extends HttpFactory { +class AdminApiClient extends ApiClient { async evictRegionCache(): Promise { return this.deleteCall(`/actuator/caches/regions`); } } -export default AdminService; +export default AdminApiClient; diff --git a/service/api/analysisApiClient.ts b/service/api/analysisApiClient.ts new file mode 100644 index 0000000..9508e68 --- /dev/null +++ b/service/api/analysisApiClient.ts @@ -0,0 +1,21 @@ +import ApiClient from "~/service/api/apiClient"; +import type { Analysis } from "../analysisService"; +import type { AnalysisDetails } from "~/service/analysisService"; + +export class AnalysisApiClient extends ApiClient { + private readonly RESOURCE = "/api/analysis"; + + async getAllAnalyses(): Promise { + return await this.getCall(this.RESOURCE); + } + + async getAnalysisById(analysisId: string): Promise { + return await this.getCall( + `${this.RESOURCE}/${analysisId}`, + ); + } + + async deleteAnalysis(analysisId: string): Promise { + return await this.deleteCall(`${this.RESOURCE}/${analysisId}`); + } +} diff --git a/service/factory/httpFactory.ts b/service/api/apiClient.ts similarity index 97% rename from service/factory/httpFactory.ts rename to service/api/apiClient.ts index 2b8ee5b..4e9c1b5 100644 --- a/service/factory/httpFactory.ts +++ b/service/api/apiClient.ts @@ -17,7 +17,7 @@ */ import type { ofetch } from "ofetch"; -class HttpFactory { +class ApiClient { private readonly $fetch: typeof ofetch; constructor(fetcher: typeof ofetch) { @@ -86,4 +86,4 @@ class HttpFactory { } } -export default HttpFactory; +export default ApiClient; diff --git a/service/catalogService.ts b/service/api/catalogApiClient.ts similarity index 91% rename from service/catalogService.ts rename to service/api/catalogApiClient.ts index ec581bb..93a5956 100644 --- a/service/catalogService.ts +++ b/service/api/catalogApiClient.ts @@ -15,12 +15,12 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import HttpFactory from "~/service/factory/httpFactory"; import { Availability } from "~/type/Availability"; import type { ServiceCatalog } from "~/type/ServiceCatalog"; import type { ServiceDescription } from "~/type/ServiceDescription"; +import ApiClient from "~/service/api/apiClient"; -class CatalogService extends HttpFactory { +class CatalogApiClient extends ApiClient { private readonly RESOURCE = "/api/public/v2/catalog"; async getAllServices(): Promise { @@ -39,4 +39,4 @@ class CatalogService extends HttpFactory { } } -export default CatalogService; +export default CatalogApiClient; diff --git a/service/componentService.ts b/service/api/componentApiClient.ts similarity index 85% rename from service/componentService.ts rename to service/api/componentApiClient.ts index 6823731..6418567 100644 --- a/service/componentService.ts +++ b/service/api/componentApiClient.ts @@ -15,17 +15,18 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import HttpFactory from "./factory/httpFactory"; +import ApiClient from "./apiClient"; import type { Component } from "~/type/infrastructure/Component"; import type { SaveComponentRequest } from "~/type/infrastructure/SaveComponentRequest"; import type { UpdateComponentRequest } from "~/type/infrastructure/UpdateComponentRequest"; -class ComponentService extends HttpFactory { +class ComponentApiClient extends ApiClient { private readonly RESOURCE = "/api/v2/components"; async getComponentsByInfrastructureId(id: string): Promise { - const url = this.RESOURCE; - return await this.getCall(url, undefined, { infrastructureId: id }); + return await this.getCall(this.RESOURCE, undefined, { + infrastructureId: id, + }); } async saveComponent(component: SaveComponentRequest): Promise { return await this.postCall(this.RESOURCE, component); @@ -39,4 +40,4 @@ class ComponentService extends HttpFactory { } } -export default ComponentService; +export default ComponentApiClient; diff --git a/service/curService.ts b/service/api/curApiClient.ts similarity index 93% rename from service/curService.ts rename to service/api/curApiClient.ts index a5ec506..a355f43 100644 --- a/service/curService.ts +++ b/service/api/curApiClient.ts @@ -15,14 +15,15 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import HttpFactory from "./factory/httpFactory"; + +import ApiClient from "~/service/api/apiClient"; type ServerResponse = { analysisId: string; presignedUrl: string; }; -export default class CurService extends HttpFactory { +export default class CurApiClient extends ApiClient { private readonly PRESIGNED_URL = "/api/analysis/presigned-url"; async uploadFile(file: File) { diff --git a/service/infrastructureService.ts b/service/api/infrastructureApiClient.ts similarity index 91% rename from service/infrastructureService.ts rename to service/api/infrastructureApiClient.ts index 912af08..0c43d45 100644 --- a/service/infrastructureService.ts +++ b/service/api/infrastructureApiClient.ts @@ -16,10 +16,10 @@ * SPDX-License-Identifier: Apache-2.0 */ import type { InfrastructureRequest } from "~/type/infrastructure/InfrastructureRequest"; -import HttpFactory from "./factory/httpFactory"; +import ApiClient from "./apiClient"; import type { Infrastructure } from "~/type/infrastructure/Infrastructure"; -class InfrastructureService extends HttpFactory { +class InfrastructureApiClient extends ApiClient { private readonly RESOURCE = "/api/v2/infrastructures"; async createNewInfra( @@ -43,4 +43,4 @@ class InfrastructureService extends HttpFactory { } } -export default InfrastructureService; +export default InfrastructureApiClient; diff --git a/service/api/irocalcCarbonApiClient.ts b/service/api/irocalcCarbonApiClient.ts new file mode 100644 index 0000000..9b21936 --- /dev/null +++ b/service/api/irocalcCarbonApiClient.ts @@ -0,0 +1,19 @@ +import ApiClient from "~/service/api/apiClient"; +import type { CarbonFootprintEstimateComponent } from "~/type/CarbonFootprintEstimateComponent"; +import type { RegionCarbonFootprint } from "~/type/RegionCarbonFootprint"; + +export class IrocalcCarbonApiClient extends ApiClient { + private readonly RESOURCE = "/api/v2/infrastructures"; + + async getCarbonFootprintEstimateComponents(infrastructureId: string) { + return await this.getCall( + `${this.RESOURCE}/${infrastructureId}/carbon-footprint`, + ); + } + + async getEstimatedCO2ByRegion(infrastructureId: string) { + return await this.getCall( + `${this.RESOURCE}/${infrastructureId}/byregion-carbon-footprint`, + ); + } +} diff --git a/service/api/scanApiClient.ts b/service/api/scanApiClient.ts new file mode 100644 index 0000000..21e642e --- /dev/null +++ b/service/api/scanApiClient.ts @@ -0,0 +1,32 @@ +/* + * Copyright 2025 Ippon Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +import ApiClient from "./apiClient"; +import type { Scan, ScanDetails } from "~/type/Scan"; + +class ScanApiClient extends ApiClient { + private readonly RESOURCE = "/api/scanner"; + async getAllScans(): Promise { + return await this.getCall(this.RESOURCE); + } + + async getScanById(scanId: string): Promise { + return await this.getCall(`${this.RESOURCE}/${scanId}`); + } +} + +export default ScanApiClient; diff --git a/service/awsDataCenterService.ts b/service/awsDataCenterService.ts index dad4b08..02c8192 100644 --- a/service/awsDataCenterService.ts +++ b/service/awsDataCenterService.ts @@ -15,38 +15,34 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import type { $Fetch } from "ofetch"; -import ComponentService from "./componentService"; -import HttpFactory from "./factory/httpFactory"; import type { Region } from "~/type/Region"; -import InfrastructureService from "~/service/infrastructureService"; +import type InfrastructureApiClient from "~/service/api/infrastructureApiClient"; +import type { AWSDataCenterApiClient } from "~/service/api/AWSDataCenterApiClient"; -class AWSDataCenterService extends HttpFactory { - private readonly RESOURCE = "/api/cloud-service-providers"; - private readonly componentService: ComponentService; - private readonly infrastructureService: InfrastructureService; +class AWSDataCenterService { + private readonly infrastructureApiClient: InfrastructureApiClient; + private readonly awsDataCenterApiClient: AWSDataCenterApiClient; - constructor(fetcher: $Fetch) { - super(fetcher); - this.componentService = new ComponentService(fetcher); - this.infrastructureService = new InfrastructureService(fetcher); + constructor( + infrastructureApiClient: InfrastructureApiClient, + awsDataCenterApiClient: AWSDataCenterApiClient, + ) { + this.infrastructureApiClient = infrastructureApiClient; + this.awsDataCenterApiClient = awsDataCenterApiClient; } async getAllAWSDataCenter(): Promise { const cspId = await useCloudServiceProviderStore().getCloudServiceProviderID("AWS"); - return await this.getCall(`${this.RESOURCE}/${cspId}/regions`); + return await this.awsDataCenterApiClient.getAllAWSDataCenter(cspId); } async getRegionByInfrastructureId(infrastructureId: string) { const infrastructure = - await this.infrastructureService.getInfrastructure(infrastructureId); + await this.infrastructureApiClient.getInfrastructure(infrastructureId); const regions = await this.getAllAWSDataCenter(); - const currentRegion = regions.find( - (region) => region.id === infrastructure.defaultRegion, - ); - return currentRegion; + return regions.find((region) => region.id === infrastructure.defaultRegion); } } diff --git a/service/carbonService.ts b/service/carbonService.ts index 9cb6f92..9b3a16a 100644 --- a/service/carbonService.ts +++ b/service/carbonService.ts @@ -15,18 +15,20 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import HttpFactory from "~/service/factory/httpFactory"; -import type { CarbonFootprintEstimateComponent } from "~/type/CarbonFootprintEstimateComponent"; -import type { RegionCarbonFootprint } from "~/type/RegionCarbonFootprint"; +import type { IrocalcCarbonApiClient } from "~/service/api/irocalcCarbonApiClient"; -class IrocalcCarbonService extends HttpFactory { - private readonly RESOURCE = "/api/v2/infrastructures"; +class IrocalcCarbonService { + private readonly irocalcCarbonApiClient: IrocalcCarbonApiClient; - async estimateCarbonFootPrint(infrastructureId: string) { - const url = `${this.RESOURCE}/${infrastructureId}/carbon-footprint`; + constructor(irocalcCarbonApiClient: IrocalcCarbonApiClient) { + this.irocalcCarbonApiClient = irocalcCarbonApiClient; + } + async estimateCarbonFootPrint(infrastructureId: string) { const estimated = ( - await this.getCall(url) + await this.irocalcCarbonApiClient.getCarbonFootprintEstimateComponents( + infrastructureId, + ) ).map((e) => ({ label: e.componentName, co2Gr: e.co2Gr, @@ -44,10 +46,10 @@ class IrocalcCarbonService extends HttpFactory { infrastructureId: string, totalCO2Gr: number, ) { - const url = `${this.RESOURCE}/${infrastructureId}/byregion-carbon-footprint`; - const estimatedCO2ByRegion = - await this.getCall(url); + await this.irocalcCarbonApiClient.getEstimatedCO2ByRegion( + infrastructureId, + ); const estimatedCO2WithPercentDiff = estimatedCO2ByRegion.map( (estimate) => ({ diff --git a/service/scanService.ts b/service/scanService.ts index ddcf1ff..b5d4456 100644 --- a/service/scanService.ts +++ b/service/scanService.ts @@ -15,22 +15,26 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import HttpFactory from "./factory/httpFactory"; -import type { EstimatedScan, Scan, ScanDetails } from "~/type/Scan"; +import type { EstimatedScan, Scan } from "~/type/Scan"; +import type ScanApiClient from "~/service/api/scanApiClient"; + +class ScanService { + private readonly scanApiClient: ScanApiClient; + + constructor(scanApiClient: ScanApiClient) { + this.scanApiClient = scanApiClient; + } -class ScanService extends HttpFactory { - private readonly RESOURCE = "/api/scanner"; async getAllScans(): Promise { - const scans = await this.getCall(this.RESOURCE); - const scansWithCO2Converted = scans.map((scan) => ({ + const scans = await this.scanApiClient.getAllScans(); + return scans.map((scan) => ({ ...scan, co2Converted: convertEstimateToBestMassUnit(scan.co2Gr), })); - return scansWithCO2Converted; } async getScanById(scanId: string): Promise { - const scans = await this.getCall(`${this.RESOURCE}/${scanId}`); + const scans = await this.scanApiClient.getScanById(scanId); const estimated = scans.payloads.map((p) => ({ label: p.name, diff --git a/service/tokenService.ts b/service/tokenService.ts index dd8a35c..2b17d9c 100644 --- a/service/tokenService.ts +++ b/service/tokenService.ts @@ -16,9 +16,9 @@ * SPDX-License-Identifier: Apache-2.0 */ import type { GetTokenRequest } from "~/type/GetTokenRequest"; -import HttpFactory from "./factory/httpFactory"; +import ApiClient from "~/service/api/apiClient"; -class TokenService extends HttpFactory { +class TokenService extends ApiClient { private readonly RESOURCE = "/api/v1/token/generate"; async getToken(body: GetTokenRequest): Promise { return await this.postCall(this.RESOURCE, body); diff --git a/stores/cloud-service-provider.store.ts b/stores/cloud-service-provider.store.ts index 26b3beb..af44d3f 100644 --- a/stores/cloud-service-provider.store.ts +++ b/stores/cloud-service-provider.store.ts @@ -25,7 +25,7 @@ export const useCloudServiceProviderStore = defineStore( const fetchCloudServiceProviders = async () => { if (cloudServiceProviders.value.length === 0) cloudServiceProviders.value = - await useNuxtApp().$api.cloudServiceProviderService.getCloudServiceProviders(); + await useNuxtApp().$api.cloudServiceProviderApiClient.getCloudServiceProviders(); }; const getRegionBy = async (param: string, paramType: "id" | "name") => { diff --git a/stores/infrastructures.store.ts b/stores/infrastructures.store.ts index 8f3b677..048d7be 100644 --- a/stores/infrastructures.store.ts +++ b/stores/infrastructures.store.ts @@ -22,7 +22,7 @@ export const useInfrastructuresStore = defineStore("infrastructures", () => { const fetchInfrastructures = async () => { infrastructures.value = - await useNuxtApp().$api.infrastructureService.getInfrastructures(); + await useNuxtApp().$api.infrastructureApiClient.getInfrastructures(); }; return { diff --git a/test/components/AddAnalysisAlert.spec.ts b/test/components/AddAnalysisAlert.spec.ts index 6187066..40ea702 100644 --- a/test/components/AddAnalysisAlert.spec.ts +++ b/test/components/AddAnalysisAlert.spec.ts @@ -30,7 +30,7 @@ const { mockUploadFile } = vi.hoisted(() => ({ mockNuxtImport("useNuxtApp", () => { return () => ({ $api: { - curService: { + curApiClient: { uploadFile: mockUploadFile, }, }, @@ -42,7 +42,7 @@ describe("AddAnalysisAlert component", () => { mockNuxtImport("useNuxtApp", () => { return () => ({ $api: { - curService: { + curApiClient: { uploadFile: mockUploadFile, }, }, diff --git a/test/components/ConfigurationSettingsConfigurationSetting.spec.ts b/test/components/ConfigurationSettingsConfigurationSetting.spec.ts index 3ad7a2d..0dc92c0 100644 --- a/test/components/ConfigurationSettingsConfigurationSetting.spec.ts +++ b/test/components/ConfigurationSettingsConfigurationSetting.spec.ts @@ -91,7 +91,7 @@ describe("ConfigurationSettingsConfigurationSetting component", () => { mockNuxtImport("useNuxtApp", () => { return () => ({ $api: { - instanceType: { + awsInstanceApiClient: { getAllInstanceByType: mockGetAllInstanceByType, }, }, diff --git a/test/pages/catalog.test.ts b/test/pages/catalog.test.ts index 478d8ab..5116ba5 100644 --- a/test/pages/catalog.test.ts +++ b/test/pages/catalog.test.ts @@ -15,7 +15,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { VueWrapper } from "@vue/test-utils"; import { mount } from "@vue/test-utils"; import Catalog from "~/pages/catalog/index.vue"; @@ -33,7 +33,7 @@ describe("Catalog page", async () => { mockNuxtImport("useNuxtApp", () => { return () => ({ $api: { - catalogService: { + catalogApiClient: { getAllServices: mockGetAllService.mockResolvedValue(catalogResponse), }, diff --git a/test/services/CloudServiceProviderService.spec.ts b/test/services/CloudServiceProviderService.spec.ts index c429244..c6d5a3c 100644 --- a/test/services/CloudServiceProviderService.spec.ts +++ b/test/services/CloudServiceProviderService.spec.ts @@ -18,7 +18,7 @@ import type { $Fetch } from "ofetch"; import { mockNuxtImport } from "@nuxt/test-utils/runtime"; import type { Mock } from "vitest"; -import CloudServiceProviderSvc from "~/service/CloudServiceProviderService"; +import CloudServiceProviderApiClient from "~/service/api/CloudServiceProviderApiClient"; import type { CloudServiceProvider } from "~/type/infrastructure/CloudServiceProvider"; import type { CloudServiceProviderService } from "~/type/infrastructure/CloudServiceProviderService"; @@ -35,12 +35,12 @@ mockNuxtImport("useCloudServiceProviderStore", () => { }); describe("CloudServiceProviderService", () => { - let cloudServiceProviderService: CloudServiceProviderSvc; + let cloudServiceProviderService: CloudServiceProviderApiClient; let mockFetch: Mock; beforeEach(() => { mockFetch = vi.fn(); - cloudServiceProviderService = new CloudServiceProviderSvc( + cloudServiceProviderService = new CloudServiceProviderApiClient( mockFetch as unknown as $Fetch, ); }); diff --git a/test/services/analysisService.spec.ts b/test/services/analysisService.spec.ts index ecb0c1e..c2bbdd7 100644 --- a/test/services/analysisService.spec.ts +++ b/test/services/analysisService.spec.ts @@ -18,6 +18,7 @@ import type { $Fetch } from "ofetch"; import type { Mock } from "vitest"; import AnalysisService from "~/service/analysisService"; +import { AnalysisApiClient } from "~/service/api/analysisApiClient"; const ANALYSIS_API_URL = "/api/analysis"; @@ -48,7 +49,9 @@ describe("AnalysisService", () => { beforeEach(() => { mockFetch = vi.fn(); - analysisService = new AnalysisService(mockFetch as unknown as $Fetch); + analysisService = new AnalysisService( + new AnalysisApiClient(mockFetch as unknown as $Fetch), + ); }); afterEach(() => { diff --git a/test/services/awsDataCenterService.spec.ts b/test/services/awsDataCenterService.spec.ts index 6af0ce3..5eac94f 100644 --- a/test/services/awsDataCenterService.spec.ts +++ b/test/services/awsDataCenterService.spec.ts @@ -16,21 +16,16 @@ * SPDX-License-Identifier: Apache-2.0 */ import AWSDataCenterService from "~/service/awsDataCenterService"; -import type { $Fetch } from "ofetch"; import { mockNuxtImport } from "@nuxt/test-utils/runtime"; import type { Mock } from "vitest"; +import type { AWSDataCenterApiClient } from "~/service/api/AWSDataCenterApiClient"; +import type InfrastructureApiClient from "~/service/api/infrastructureApiClient"; const AWS_UUID = vi.hoisted(() => "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); -const { mockGetCloudServiceProviderID, mockGetInfrastructure } = vi.hoisted( - () => ({ - mockGetCloudServiceProviderID: vi.fn().mockResolvedValue(AWS_UUID), - mockGetInfrastructure: vi.fn().mockResolvedValue({ - id: "infra1", - defaultRegion: "region2", - }), - }), -); +const { mockGetCloudServiceProviderID } = vi.hoisted(() => ({ + mockGetCloudServiceProviderID: vi.fn().mockResolvedValue(AWS_UUID), +})); mockNuxtImport("useCloudServiceProviderStore", () => { return () => ({ @@ -38,20 +33,26 @@ mockNuxtImport("useCloudServiceProviderStore", () => { }); }); -vi.mock("~/service/infrastructureService", () => ({ - default: vi.fn().mockImplementation(() => ({ - getInfrastructure: mockGetInfrastructure, - })), -})); - describe("AWSDataCenterService", () => { let awsDataCenterService: AWSDataCenterService; - let mockFetch: Mock; + let mockInfrastructureApiClient: InfrastructureApiClient; + let mockAWSDataCenterApiClient: AWSDataCenterApiClient; beforeEach(() => { - mockFetch = vi.fn(); + mockInfrastructureApiClient = { + getInfrastructure: vi.fn().mockResolvedValue({ + id: "infra1", + defaultRegion: "region2", + }), + } as unknown as InfrastructureApiClient; + + mockAWSDataCenterApiClient = { + getAllAWSDataCenter: vi.fn(), + } as unknown as AWSDataCenterApiClient; + awsDataCenterService = new AWSDataCenterService( - mockFetch as unknown as $Fetch, + mockInfrastructureApiClient, + mockAWSDataCenterApiClient, ); }); @@ -66,24 +67,25 @@ describe("AWSDataCenterService", () => { it("fetches all AWS data centers", async () => { // Arrange - mockFetch.mockResolvedValue(mockRegions); + (mockAWSDataCenterApiClient.getAllAWSDataCenter as Mock).mockResolvedValue( + mockRegions, + ); // Act const regions = await awsDataCenterService.getAllAWSDataCenter(); // Assert expect(regions).toEqual(mockRegions); - expect(mockFetch).toHaveBeenCalledWith( - `/api/cloud-service-providers/${AWS_UUID}/regions`, - expect.objectContaining({ - method: "GET", - }), + expect(mockAWSDataCenterApiClient.getAllAWSDataCenter).toHaveBeenCalledWith( + AWS_UUID, ); }); it("fetches the correct region by infrastructure ID", async () => { // Arrange - mockFetch.mockResolvedValue(mockRegions); + (mockAWSDataCenterApiClient.getAllAWSDataCenter as Mock).mockResolvedValue( + mockRegions, + ); // Act const region = @@ -91,18 +93,15 @@ describe("AWSDataCenterService", () => { // Assert expect(region).toEqual(mockRegions[1]); - expect(mockFetch).toHaveBeenCalledWith( - `/api/cloud-service-providers/${AWS_UUID}/regions`, - expect.objectContaining({ - method: "GET", - }), + expect(mockAWSDataCenterApiClient.getAllAWSDataCenter).toHaveBeenCalled(); + expect(mockInfrastructureApiClient.getInfrastructure).toHaveBeenCalledWith( + "infra1", ); - expect(mockGetInfrastructure).toHaveBeenCalledWith("infra1"); }); it("returns undefined if no region matches the default region", async () => { // Arrange - mockFetch.mockResolvedValue([ + (mockAWSDataCenterApiClient.getAllAWSDataCenter as Mock).mockResolvedValue([ { id: "region1", name: "Region 1", csp: AWS_UUID }, { id: "region3", name: "Region 3", csp: AWS_UUID }, ]); @@ -113,12 +112,9 @@ describe("AWSDataCenterService", () => { // Assert expect(region).toBeUndefined(); - expect(mockFetch).toHaveBeenCalledWith( - `/api/cloud-service-providers/${AWS_UUID}/regions`, - expect.objectContaining({ - method: "GET", - }), + expect(mockAWSDataCenterApiClient.getAllAWSDataCenter).toHaveBeenCalled(); + expect(mockInfrastructureApiClient.getInfrastructure).toHaveBeenCalledWith( + "infra1", ); - expect(mockGetInfrastructure).toHaveBeenCalledWith("infra1"); }); }); diff --git a/test/services/awsInstanceService.spec.ts b/test/services/awsInstanceService.spec.ts index 6439f4f..49d4036 100644 --- a/test/services/awsInstanceService.spec.ts +++ b/test/services/awsInstanceService.spec.ts @@ -17,16 +17,18 @@ */ import type { $Fetch } from "ofetch"; import type { Mock } from "vitest"; -import AWSInstanceService from "~/service/awsInstanceService"; +import AWSInstanceApiClient from "~/service/api/AWSInstanceApiClient"; import type { EC2InstanceType } from "~/type/ec2InstanceType"; describe("AWSInstanceService", () => { - let awsInstanceService: AWSInstanceService; + let awsInstanceService: AWSInstanceApiClient; let mockFetch: Mock; beforeEach(() => { mockFetch = vi.fn(); - awsInstanceService = new AWSInstanceService(mockFetch as unknown as $Fetch); + awsInstanceService = new AWSInstanceApiClient( + mockFetch as unknown as $Fetch, + ); }); afterEach(() => { diff --git a/test/services/carbonService.spec.ts b/test/services/carbonService.spec.ts index 14d2978..2def1f8 100644 --- a/test/services/carbonService.spec.ts +++ b/test/services/carbonService.spec.ts @@ -18,6 +18,7 @@ import type { $Fetch } from "ofetch"; import type { Mock } from "vitest"; import IrocalcCarbonService from "~/service/carbonService"; +import { IrocalcCarbonApiClient } from "~/service/api/irocalcCarbonApiClient"; describe("CarbonService", () => { let carbonService: IrocalcCarbonService; @@ -26,7 +27,9 @@ describe("CarbonService", () => { beforeEach(() => { mockFetch = vi.fn(); - carbonService = new IrocalcCarbonService(mockFetch as unknown as $Fetch); + carbonService = new IrocalcCarbonService( + new IrocalcCarbonApiClient(mockFetch as unknown as $Fetch), + ); }); afterEach(() => { diff --git a/test/services/catalogService.spec.ts b/test/services/catalogService.spec.ts index 18b8be3..fd90884 100644 --- a/test/services/catalogService.spec.ts +++ b/test/services/catalogService.spec.ts @@ -17,18 +17,18 @@ */ import type { $Fetch } from "ofetch"; import type { Mock } from "vitest"; -import CatalogService from "~/service/catalogService"; +import CatalogApiClient from "~/service/api/catalogApiClient"; import type { ServiceCatalog } from "~/type/ServiceCatalog"; import { Availability } from "~/type/Availability"; import type { ServiceDescription } from "~/type/ServiceDescription"; describe("CatalogService", () => { - let catalogService: CatalogService; + let catalogApiClient: CatalogApiClient; let mockFetch: Mock; beforeEach(() => { mockFetch = vi.fn(); - catalogService = new CatalogService(mockFetch as unknown as $Fetch); + catalogApiClient = new CatalogApiClient(mockFetch as unknown as $Fetch); }); afterEach(() => { @@ -74,7 +74,7 @@ describe("CatalogService", () => { ]; // Act - const services = await catalogService.getAllServices(); + const services = await catalogApiClient.getAllServices(); // Assert expect(services).toEqual(expectedSortedCatalog); @@ -119,7 +119,7 @@ describe("CatalogService", () => { mockFetch.mockResolvedValue(serviceDescription); // Act - const description = await catalogService.getById(serviceId); + const description = await catalogApiClient.getById(serviceId); // Assert expect(description).toEqual(serviceDescription); diff --git a/test/services/curService.spec.ts b/test/services/curService.spec.ts index da6c15e..0620d02 100644 --- a/test/services/curService.spec.ts +++ b/test/services/curService.spec.ts @@ -17,7 +17,7 @@ */ import type { $Fetch } from "ofetch"; import type { Mock } from "vitest"; -import CurService from "~/service/curService"; +import CurApiClient from "~/service/api/curApiClient"; const PRESIGNED_URL_ENDPOINT = "/api/analysis/presigned-url"; const MOCK_PRESIGNED_URL = @@ -30,7 +30,7 @@ const MOCK_SERVER_RESPONSE = { }; describe("CurService", () => { - let curService: CurService; + let curApiClient: CurApiClient; let mockFetch: Mock; let mockGlobalFetch: Mock; @@ -38,7 +38,7 @@ describe("CurService", () => { mockFetch = vi.fn(); mockGlobalFetch = vi.fn(); global.fetch = mockGlobalFetch; - curService = new CurService(mockFetch as unknown as $Fetch); + curApiClient = new CurApiClient(mockFetch as unknown as $Fetch); }); afterEach(() => { @@ -53,7 +53,7 @@ describe("CurService", () => { mockGlobalFetch.mockResolvedValue({ ok: true }); // when - await curService.uploadFile(file); + await curApiClient.uploadFile(file); // then expect(mockFetch).toHaveBeenCalledWith( @@ -77,7 +77,7 @@ describe("CurService", () => { mockGlobalFetch.mockResolvedValue({ ok: true }); // when - await curService.uploadFile(file); + await curApiClient.uploadFile(file); // then expect(mockFetch).toHaveBeenCalledWith( @@ -101,7 +101,7 @@ describe("CurService", () => { mockGlobalFetch.mockResolvedValue({ ok: true }); // when - await curService.uploadFile(file); + await curApiClient.uploadFile(file); // then expect(mockFetch).toHaveBeenCalledWith( @@ -119,7 +119,7 @@ describe("CurService", () => { mockFetch.mockRejectedValue(error); // when - const promise = curService.uploadFile(file); + const promise = curApiClient.uploadFile(file); // then await expect(promise).rejects.toThrow("Failed to get presigned URL"); @@ -138,7 +138,7 @@ describe("CurService", () => { mockGlobalFetch.mockRejectedValue(error); // when - const promise = curService.uploadFile(file); + const promise = curApiClient.uploadFile(file); // then await expect(promise).rejects.toThrow("S3 upload failed"); diff --git a/test/services/scanService.spec.ts b/test/services/scanService.spec.ts index 1394008..f6f3f3d 100644 --- a/test/services/scanService.spec.ts +++ b/test/services/scanService.spec.ts @@ -19,6 +19,7 @@ import type { Mock } from "vitest"; import ScanService from "~/service/scanService"; import type { $Fetch } from "ofetch"; import type { ReportStatus } from "~/type/ReportStatus"; +import ScanApiClient from "~/service/api/scanApiClient"; describe("scanService", () => { let scanService: ScanService; @@ -26,7 +27,9 @@ describe("scanService", () => { beforeEach(() => { mockFetch = vi.fn(); - scanService = new ScanService(mockFetch as unknown as $Fetch); + scanService = new ScanService( + new ScanApiClient(mockFetch as unknown as $Fetch), + ); }); afterEach(() => { diff --git a/test/stores/cloud-service-provider.store.spec.ts b/test/stores/cloud-service-provider.store.spec.ts index 13e1830..e792a8e 100644 --- a/test/stores/cloud-service-provider.store.spec.ts +++ b/test/stores/cloud-service-provider.store.spec.ts @@ -35,7 +35,7 @@ const { mockGetCloudServiceProviders } = vi.hoisted(() => ({ mockNuxtImport("useNuxtApp", () => { return () => ({ $api: { - cloudServiceProviderService: { + cloudServiceProviderApiClient: { getCloudServiceProviders: mockGetCloudServiceProviders, }, }, diff --git a/test/stores/infrastructure.store.spec.ts b/test/stores/infrastructure.store.spec.ts index 8f4df5f..79af72b 100644 --- a/test/stores/infrastructure.store.spec.ts +++ b/test/stores/infrastructure.store.spec.ts @@ -44,7 +44,7 @@ const { mockGetInfrastructures } = vi.hoisted(() => ({ mockNuxtImport("useNuxtApp", () => { return () => ({ $api: { - infrastructureService: { + infrastructureApiClient: { getInfrastructures: mockGetInfrastructures, }, },