Skip to content

Commit

Permalink
Change spelling (m/M)etaData -> (m/M)etadata
Browse files Browse the repository at this point in the history
  • Loading branch information
david-mears-2 committed Sep 5, 2024
1 parent 4dcc7c0 commit 19dc5db
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
12 changes: 6 additions & 6 deletions components/ParameterForm.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div>
<CForm
v-if="props.metaData && formData"
v-if="props.metadata && formData"
class="inputs"
:data-test="JSON.stringify(formData)"
@submit.prevent="submitForm"
>
<div
v-for="(parameter) in props.metaData.parameters"
v-for="(parameter) in props.metadata.parameters"
:key="parameter.id"
class="field-container"
>
Expand Down Expand Up @@ -83,18 +83,18 @@
<script lang="ts" setup>
import type { FetchError } from "ofetch";
import { CIcon } from "@coreui/icons-vue";
import type { MetaData, Parameter } from "@/types/daedalusApiResponseTypes";
import type { Metadata, Parameter } from "@/types/daedalusApiResponseTypes";
import type { AsyncDataRequestStatus } from "#app";
const props = defineProps<{
metaData: MetaData | undefined
metadata: Metadata | undefined
metadataFetchStatus: AsyncDataRequestStatus
metadataFetchError: FetchError | null
}>();
const formData = ref(
// Create a new object with keys set to the id values of the metaData.parameters array of objects, and all values set to refs with default values.
props.metaData?.parameters.reduce((accumulator, parameter) => {
// Create a new object with keys set to the id values of the metadata.parameters array of objects, and all values set to refs with default values.
props.metadata?.parameters.reduce((accumulator, parameter) => {
if (parameter.parameterType !== "select" && parameter.parameterType !== "globeSelect") {
accumulator[parameter.id] = ref("");
return accumulator;
Expand Down
12 changes: 6 additions & 6 deletions pages/scenarios/new.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h3>Simulate a new scenario</h3>
<p>Select the parameters for your next scenario.</p>
<ParameterForm
:meta-data="metaData"
:metadata="metadata"
:metadata-fetch-status="metadataFetchStatus"
:metadata-fetch-error="metadataFetchError"
/>
Expand All @@ -16,17 +16,17 @@
<script lang="ts" setup>
import type { FetchError } from "ofetch";
import type { AsyncDataRequestStatus } from "#app";
import type { MetaData } from "@/types/daedalusApiResponseTypes";
import type { Metadata } from "@/types/daedalusApiResponseTypes";
const { data: metaData, status: metadataFetchStatus, error: metadataFetchError } = useFetch("/api/metadata") as {
data: Ref<MetaData>
const { data: metadata, status: metadataFetchStatus, error: metadataFetchError } = useFetch("/api/metadata") as {
data: Ref<Metadata>
status: Ref<AsyncDataRequestStatus>
error: Ref<FetchError | null>
};
const globeParameter = computed(() => {
if (metaData.value) {
return metaData.value.parameters.filter(parameter => parameter.parameterType === "globeSelect")[0];
if (metadata.value) {
return metadata.value.parameters.filter(parameter => parameter.parameterType === "globeSelect")[0];
} else {
return undefined;
}
Expand Down
12 changes: 6 additions & 6 deletions server/api/metadata.get.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getMetaData } from "@/server/handlers/metadata";
import { getMetadata } from "@/server/handlers/metadata";
import { defineRApiEventHandler } from "~/server/utils/defineRApiEventHandler";
import type { MetaDataResponse } from "@/types/daedalusApiResponseTypes";
import type { MetadataResponse } from "@/types/daedalusApiResponseTypes";

export default defineRApiEventHandler(
async (event): Promise<MetaDataResponse> => {
// Delegate to getMetaData so that the logic can be unit-tested.
const metaDataResponse = await getMetaData(event);
async (event): Promise<MetadataResponse> => {
// Delegate to getMetadata so that the logic can be unit-tested.
const metadataResponse = await getMetadata(event);

return metaDataResponse;
return metadataResponse;
},
);
10 changes: 5 additions & 5 deletions server/handlers/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { EventHandlerRequest, H3Event } from "h3";
import { fetchRApi } from "@/server/utils/rApi";
import type { MetaData, MetaDataResponse } from "@/types/daedalusApiResponseTypes";
import type { Metadata, MetadataResponse } from "@/types/daedalusApiResponseTypes";

const rApiMetadataEndpoint = "/metadata";

export const getMetaData = async (event?: H3Event<EventHandlerRequest>): Promise<MetaDataResponse> => {
const response = await fetchRApi<MetaData>( // Since we aren't transforming the R API's response, we can re-use the type interface for the web app's response (MetaData) as the interface for the R API's response.
export const getMetadata = async (event?: H3Event<EventHandlerRequest>): Promise<MetadataResponse> => {
const response = await fetchRApi<Metadata>( // Since we aren't transforming the R API's response, we can re-use the type interface for the web app's response (Metadata) as the interface for the R API's response.
rApiMetadataEndpoint,
{},
event,
Expand All @@ -15,6 +15,6 @@ export const getMetaData = async (event?: H3Event<EventHandlerRequest>): Promise
statusText: response.statusText,
statusCode: response.statusCode,
errors: response?.errors || null,
data: response?.data as MetaData,
} as MetaDataResponse;
data: response?.data as Metadata,
} as MetadataResponse;
};
12 changes: 6 additions & 6 deletions tests/unit/components/ParameterForm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ const selectParameters = [
},
];

const metaData = { modelVersion: "0.0.0", parameters: [...selectParameters, globeParameter] };
const metadata = { modelVersion: "0.0.0", parameters: [...selectParameters, globeParameter] };

describe("parameter form", () => {
it("adds a resize event listener on mount and removes it on unmount", async () => {
const addEventListenerSpy = vi.spyOn(window, "addEventListener");
const removeEventListenerSpy = vi.spyOn(window, "removeEventListener");

const component = await mountSuspended(ParameterForm, {
props: { metaData: undefined, metadataFetchStatus: "pending", metadataFetchError: null },
props: { metadata: undefined, metadataFetchStatus: "pending", metadataFetchError: null },
global: { stubs },
});
expect(addEventListenerSpy).toHaveBeenCalledWith("resize", expect.any(Function));
Expand All @@ -71,7 +71,7 @@ describe("parameter form", () => {

it("renders the correct parameter labels, inputs, options, and default values", async () => {
const component = await mountSuspended(ParameterForm, {
props: { metaData, metadataFetchStatus: "success", metadataFetchError: null },
props: { metadata, metadataFetchStatus: "success", metadataFetchError: null },
global: { stubs },
});

Expand Down Expand Up @@ -122,7 +122,7 @@ describe("parameter form", () => {

it("initialises formData with defaults and updates formData when a parameter is changed", async () => {
const component = await mountSuspended(ParameterForm, {
props: { metaData, metadataFetchStatus: "success", metadataFetchError: null },
props: { metadata, metadataFetchStatus: "success", metadataFetchError: null },
global: { stubs },
});

Expand Down Expand Up @@ -157,7 +157,7 @@ describe("parameter form", () => {
const error = new FetchError("There was a bee-related issue.");

const component = await mountSuspended(ParameterForm, {
props: { metaData: undefined, metadataFetchStatus: "error", metadataFetchError: error },
props: { metadata: undefined, metadataFetchStatus: "error", metadataFetchError: error },
global: { stubs },
});

Expand All @@ -168,7 +168,7 @@ describe("parameter form", () => {

it("displays CSpinner when metadataFetchStatus is 'pending'", async () => {
const component = await mountSuspended(ParameterForm, {
props: { metaData: undefined, metadataFetchStatus: "pending", metadataFetchError: null },
props: { metadata: undefined, metadataFetchStatus: "pending", metadataFetchError: null },
global: { stubs },
});

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/server/handlers/metadata.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, expect, it, vi } from "vitest";
import { registerEndpoint } from "@nuxt/test-utils/runtime";
import { getMetaData } from "@/server/handlers/metadata";
import { getMetadata } from "@/server/handlers/metadata";

const mockedVersionResponse = vi.fn();
const exampleMetaData = {
const exampleMetadata = {
modelVersion: "0.1.0",
parameters: [
{
Expand Down Expand Up @@ -40,13 +40,13 @@ describe("get metadata", () => {
return {
status: "success",
errors: null,
data: exampleMetaData,
data: exampleMetadata,
};
});

const response = await getMetaData();
const response = await getMetadata();

expect(response.data).toEqual(exampleMetaData);
expect(response.data).toEqual(exampleMetadata);
expect(response.errors).toBeNull();
expect(response.statusCode).toBe(200);
expect(response.statusText).toBe("");
Expand All @@ -62,7 +62,7 @@ describe("get metadata", () => {
});
});

const response = await getMetaData();
const response = await getMetadata();

// NB Couldn't find a way to expose error details in the response using registerEndpoint,
// but the error details are passed on in the real implementation and this is tested in
Expand Down
4 changes: 2 additions & 2 deletions types/daedalusApiResponseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export interface Parameter {
ordered: boolean
options: Array<ParameterOption>
}
export interface MetaData {
export interface Metadata {
modelVersion: string
parameters: Array<Parameter>
}

export interface MetaDataResponse extends ApiResponse<MetaData> { }
export interface MetadataResponse extends ApiResponse<Metadata> { }

0 comments on commit 19dc5db

Please sign in to comment.