

//[zipcode].ts
import type { NextApiRequest, NextApiResponse } from "next";
import { findByZip } from "@/mongoose/weather/services";
import dbConnect from "@/middleware/db-connect";
dbConnect();
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
): Promise<NextApiResponse<WeatherDetailType> | void> {
let data = await findByZip(req.query.zipcode as string);
return res.status(200).json(data);
}

//zipcode.e2e.test.ts
describe("The API /v1/weather/[zipcode]", () => {
test("returns the correct data from the zipcode 96815", async () => {
const zip = "96815";
let response = await fetch(`http://localhost:3002/api/v1/weather/${zip}`);
let body = await response.json();
expect(body.zip).toEqual(zip);
})
})
