Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/api/v1/airline/[airlineId]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { afterAll, afterEach, beforeEach, describe, expect, it } from "vitest"
import { TAirline } from "@/app/models/Airline"

import { getDatabase } from "@/lib/couchbase-connection"
import { uniqueTestId } from "@/lib/test-utils"
import {
DELETE as deleteHandler,
GET as getHandler,
Expand Down Expand Up @@ -82,7 +83,7 @@ describe("GET /api/v1/airline/{id}", () => {
})

describe("POST /api/v1/airline", () => {
const id = "airline_post"
const id = uniqueTestId("airline_post")
const newAirline: TAirline = {
name: "40-Mile Air",
iata: "Q5",
Expand Down Expand Up @@ -136,7 +137,7 @@ describe("POST /api/v1/airline", () => {

describe("PUT /api/v1/airline/{id}", () => {

const id = "airline_put"
const id = uniqueTestId("airline_put")

// Insert airline before running tests
beforeEach(async () => {
Expand Down Expand Up @@ -191,7 +192,7 @@ describe("PUT /api/v1/airline/{id}", () => {
})

describe("DELETE /api/v1/airline/{id}", () => {
const id = "airline_delete"
const id = uniqueTestId("airline_delete")

// Insert airline before each test. This must be awaited inside a hook: an
// unawaited call in the describe body races with the delete handler and can
Expand Down
7 changes: 4 additions & 3 deletions app/api/v1/airport/[airportId]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest"

import { getDatabase } from "@/lib/couchbase-connection"
import { TAirport } from "@/app/models/Airport"
import { uniqueTestId } from "@/lib/test-utils"

import {
DELETE as deleteHandler,
Expand Down Expand Up @@ -88,7 +89,7 @@ describe("GET /api/v1/airport/{id}", () => {
})

describe("POST /api/v1/airport/{id}", () => {
const airportId = "airport_post"
const airportId = uniqueTestId("airport_post")
const newAirport: TAirport = {
airportname: "Test Airport",
city: "Test City",
Expand Down Expand Up @@ -159,7 +160,7 @@ describe("POST /api/v1/airport/{id}", () => {
})

describe("PUT /api/v1/airport/{id}", () => {
const id = "airport_put"
const id = uniqueTestId("airport_put")

beforeEach(async () => {
await insertAirport(id, {
Expand Down Expand Up @@ -226,7 +227,7 @@ describe("PUT /api/v1/airport/{id}", () => {
})

describe("DELETE /api/v1/airport/{id}", () => {
const id = "airport_delete"
const id = uniqueTestId("airport_delete")

// Insert airport before each test. This must be awaited inside a hook: an
// unawaited call in the describe body races with the delete handler and can
Expand Down
8 changes: 4 additions & 4 deletions app/api/v1/route/[routeId]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { afterAll, afterEach, beforeEach, describe, expect, it } from "vitest"

import { getDatabase } from "@/lib/couchbase-connection"
import { TRoute } from "@/app/models/Route"
import { uniqueTestId } from "@/lib/test-utils"

import {
DELETE as deleteHandler,
Expand Down Expand Up @@ -106,7 +107,7 @@ describe("GET /api/v1/route/{id}", () => {
})

describe("POST /api/v1/route", () => {
const routeId = "route_post"
const routeId = uniqueTestId("route_post")
const newRoute: TRoute = {
airline: "AF",
airlineid: "airline_137",
Expand Down Expand Up @@ -134,7 +135,6 @@ describe("POST /api/v1/route", () => {
})

it("should respond with status code 400 when the request body is invalid", async () => {
const routeId = "route_post"
const invalidRequestBody = { invalid: "data" }

const response = await postHandler(
Expand Down Expand Up @@ -167,7 +167,7 @@ describe("POST /api/v1/route", () => {
})

describe("PUT /api/v1/route/{id}", () => {
const id = "route_put"
const id = uniqueTestId("route_put")

// Insert route before running tests
beforeEach(async () => {
Expand Down Expand Up @@ -236,7 +236,7 @@ describe("PUT /api/v1/route/{id}", () => {
})

describe("DELETE /api/v1/route/{id}", () => {
const id = "route_delete"
const id = uniqueTestId("route_delete")

// Insert route before each test. This must be awaited inside a hook: an
// unawaited call in the describe body races with the delete handler and can
Expand Down
11 changes: 11 additions & 0 deletions lib/test-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { randomUUID } from "crypto"

/**
* Returns a document ID that is unique to this test run.
*
* The CI cluster is shared with other quickstarts and with concurrent runs of
* this suite, so a fixed ID such as "route_post" can already exist (or be
* removed) by someone else mid-run. Tests that write documents must use IDs
* nobody else can collide with.
*/
export const uniqueTestId = (prefix: string) => `${prefix}_${randomUUID()}`
Loading