-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various mostly generated tests via Cursor
- Loading branch information
Showing
10 changed files
with
720 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { TRPCError } from "@trpc/server"; | ||
import { createCaller } from "../router"; | ||
|
||
describe("regionBySlug", () => { | ||
test("retrieves a region by slug and country id", async ({ | ||
fixtures, | ||
expect, | ||
}) => { | ||
const country = await fixtures.Country(); | ||
const region = await fixtures.Region({ countryId: country.id }); | ||
|
||
const caller = createCaller({ user: null }); | ||
const result = await caller.regionBySlug({ | ||
country: country.id, | ||
slug: region.slug, | ||
}); | ||
|
||
expect(result.id).toBe(region.id); | ||
expect(result.name).toBe(region.name); | ||
expect(result.slug).toBe(region.slug); | ||
}); | ||
|
||
test("retrieves a region by slug and country slug", async ({ | ||
fixtures, | ||
expect, | ||
}) => { | ||
const country = await fixtures.Country(); | ||
const region = await fixtures.Region({ countryId: country.id }); | ||
|
||
const caller = createCaller({ user: null }); | ||
const result = await caller.regionBySlug({ | ||
country: country.slug, | ||
slug: region.slug, | ||
}); | ||
|
||
expect(result.id).toBe(region.id); | ||
expect(result.name).toBe(region.name); | ||
expect(result.slug).toBe(region.slug); | ||
}); | ||
|
||
test("throws BAD_REQUEST for invalid country slug", async ({ | ||
fixtures, | ||
expect, | ||
}) => { | ||
const caller = createCaller({ user: null }); | ||
await expect( | ||
caller.regionBySlug({ | ||
country: "nonexistent-country", | ||
slug: "some-region", | ||
}), | ||
).rejects.toThrow(TRPCError); | ||
}); | ||
|
||
test("throws NOT_FOUND for non-existent region", async ({ | ||
fixtures, | ||
expect, | ||
}) => { | ||
const country = await fixtures.Country(); | ||
|
||
const caller = createCaller({ user: null }); | ||
await expect( | ||
caller.regionBySlug({ | ||
country: country.id, | ||
slug: "nonexistent-region", | ||
}), | ||
).rejects.toThrow(TRPCError); | ||
}); | ||
|
||
test("is case-insensitive for country and region slugs", async ({ | ||
fixtures, | ||
expect, | ||
}) => { | ||
const country = await fixtures.Country({ slug: "United-States" }); | ||
const region = await fixtures.Region({ | ||
countryId: country.id, | ||
slug: "California", | ||
}); | ||
|
||
const caller = createCaller({ user: null }); | ||
const result = await caller.regionBySlug({ | ||
country: "united-states", | ||
slug: "california", | ||
}); | ||
|
||
expect(result.id).toBe(region.id); | ||
expect(result.name).toBe(region.name); | ||
expect(result.slug).toBe(region.slug); | ||
}); | ||
|
||
test("returns serialized region data", async ({ fixtures, expect }) => { | ||
const country = await fixtures.Country(); | ||
const region = await fixtures.Region({ countryId: country.id }); | ||
|
||
const caller = createCaller({ user: null }); | ||
const result = await caller.regionBySlug({ | ||
country: country.id, | ||
slug: region.slug, | ||
}); | ||
|
||
expect(result.id).toBe(region.id); | ||
expect(result.name).toBe(region.name); | ||
expect(result.slug).toBe(region.slug); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.