-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: trcp recipes #1237
Merged
Merged
test: trcp recipes #1237
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
54ba5f1
experimental
UlianaPurtova ac3abfe
test: trpc recipes
UlianaPurtova e4af687
test: trpc recipes
UlianaPurtova c7fe830
test: unit test trpc recipe
UlianaPurtova cea3fa5
test: unit test trpc recipe
UlianaPurtova 7850d94
test: unit test trpc recipe
UlianaPurtova 555adbd
chore: remove unsupported jest option for testTimeout
julianpoy a6d4571
chore: update test URL for running in-container
julianpoy 20d04d3
chore: add nx test job for trpc
julianpoy adfc60e
chore: move test/utils.ts to testutils.ts
julianpoy 5fa5e89
chore: start api in CircleCI to support e2e tests
julianpoy c6a1e7a
chore: break tRPC tests into respective files
julianpoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,7 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: "trpc", | ||
preset: "../../jest.preset.js", | ||
testEnvironment: "node", | ||
testPathIgnorePatterns: ["dist/"], | ||
}; |
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,46 @@ | ||
import { trpcSetup, tearDown } from "../../testutils"; | ||
import { prisma } from "@recipesage/prisma"; | ||
import { User } from "@prisma/client"; | ||
import type { CreateTRPCProxyClient } from "@trpc/client"; | ||
import type { AppRouter } from "../../index"; | ||
import { faker } from "@faker-js/faker"; | ||
|
||
describe("createRecipe", () => { | ||
let user: User; | ||
let trpc: CreateTRPCProxyClient<AppRouter>; | ||
|
||
beforeAll(async () => { | ||
({ user, trpc } = await trpcSetup()); | ||
}); | ||
|
||
afterAll(() => { | ||
return tearDown(user.id); | ||
}); | ||
|
||
it("creates a recipe with all parameters provided", async () => { | ||
const recipe = await trpc.recipes.createRecipe.mutate({ | ||
title: faker.string.alphanumeric(10), | ||
description: faker.string.alphanumeric(10), | ||
yield: faker.string.alphanumeric(10), | ||
folder: "main", | ||
activeTime: faker.string.alphanumeric(10), | ||
totalTime: faker.string.alphanumeric(10), | ||
source: faker.string.alphanumeric(10), | ||
url: faker.string.alphanumeric(10), | ||
notes: faker.string.alphanumeric(10), | ||
ingredients: faker.string.alphanumeric(10), | ||
instructions: faker.string.alphanumeric(10), | ||
rating: faker.number.int({ min: 1, max: 5 }), | ||
labelIds: [], | ||
imageIds: [], | ||
}); | ||
|
||
expect(typeof recipe.id).toBe("string"); | ||
const response = await prisma.recipe.findUnique({ | ||
where: { | ||
id: recipe.id, | ||
}, | ||
}); | ||
expect(typeof response?.id).toBe("string"); | ||
}); | ||
}); |
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,52 @@ | ||
import { trpcSetup, tearDown } from "../../testutils"; | ||
import { prisma } from "@recipesage/prisma"; | ||
import { User } from "@prisma/client"; | ||
import type { CreateTRPCProxyClient } from "@trpc/client"; | ||
import type { AppRouter } from "../../index"; | ||
import { faker } from "@faker-js/faker"; | ||
|
||
describe("deleteRecipe", () => { | ||
let user: User; | ||
let trpc: CreateTRPCProxyClient<AppRouter>; | ||
|
||
beforeAll(async () => { | ||
({ user, trpc } = await trpcSetup()); | ||
}); | ||
|
||
afterAll(() => { | ||
return tearDown(user.id); | ||
}); | ||
|
||
it("deletes a recipe", async () => { | ||
const recipe = await prisma.recipe.create({ | ||
data: { | ||
userId: user.id, | ||
title: faker.string.alphanumeric(10), | ||
description: faker.string.alphanumeric(10), | ||
yield: faker.string.alphanumeric(10), | ||
folder: "inbox", | ||
activeTime: faker.string.alphanumeric(10), | ||
totalTime: faker.string.alphanumeric(10), | ||
source: faker.string.alphanumeric(10), | ||
url: faker.string.alphanumeric(10), | ||
notes: faker.string.alphanumeric(10), | ||
ingredients: faker.string.alphanumeric(10), | ||
instructions: faker.string.alphanumeric(10), | ||
rating: faker.number.int({ min: 1, max: 5 }), | ||
}, | ||
}); | ||
|
||
const response = await trpc.recipes.deleteRecipe.mutate({ | ||
id: recipe.id, | ||
}); | ||
|
||
expect(response).toEqual("Ok"); | ||
|
||
const response2 = await prisma.recipe.findUnique({ | ||
where: { | ||
id: recipe.id, | ||
}, | ||
}); | ||
expect(response2).toEqual(null); | ||
}); | ||
}); |
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,49 @@ | ||
import { trpcSetup, tearDown } from "../../testutils"; | ||
import { prisma } from "@recipesage/prisma"; | ||
import { User } from "@prisma/client"; | ||
import type { CreateTRPCProxyClient } from "@trpc/client"; | ||
import type { AppRouter } from "../../index"; | ||
import { faker } from "@faker-js/faker"; | ||
|
||
describe("getRecipes", () => { | ||
let user: User; | ||
let trpc: CreateTRPCProxyClient<AppRouter>; | ||
|
||
beforeAll(async () => { | ||
({ user, trpc } = await trpcSetup()); | ||
}); | ||
|
||
afterAll(() => { | ||
return tearDown(user.id); | ||
}); | ||
|
||
it("returns a list of recipes given no filters", async () => { | ||
await prisma.recipe.create({ | ||
data: { | ||
userId: user.id, | ||
title: faker.string.alphanumeric(10), | ||
description: faker.string.alphanumeric(10), | ||
yield: faker.string.alphanumeric(10), | ||
folder: "main", | ||
activeTime: faker.string.alphanumeric(10), | ||
totalTime: faker.string.alphanumeric(10), | ||
source: faker.string.alphanumeric(10), | ||
url: faker.string.alphanumeric(10), | ||
notes: faker.string.alphanumeric(10), | ||
ingredients: faker.string.alphanumeric(10), | ||
instructions: faker.string.alphanumeric(10), | ||
rating: faker.number.int({ min: 1, max: 5 }), | ||
}, | ||
}); | ||
|
||
const response = await trpc.recipes.getRecipes.query({ | ||
limit: 3, | ||
folder: "main", | ||
orderBy: "title", | ||
orderDirection: "asc", | ||
offset: 0, | ||
}); | ||
|
||
expect(typeof response.recipes[0].id).toBe("string"); | ||
}); | ||
}); |
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,65 @@ | ||
import { prisma } from "@recipesage/prisma"; | ||
import { createTRPCProxyClient, httpLink } from "@trpc/client"; | ||
import type { AppRouter } from "./index"; | ||
import superjson from "superjson"; | ||
import { faker } from "@faker-js/faker"; | ||
|
||
export async function trpcSetup() { | ||
const user = await createUser(); | ||
const session = await createSession(user.id); | ||
const trpc = await createTrpcClient(session.token as string); | ||
return { user, session, trpc }; | ||
} | ||
|
||
export async function tearDown(userId: string) { | ||
await prisma.user.delete({ | ||
where: { | ||
id: userId, | ||
}, | ||
}); | ||
} | ||
|
||
export async function createTrpcClient(token: string) { | ||
return createTRPCProxyClient<AppRouter>({ | ||
links: [ | ||
httpLink({ | ||
url: "http://localhost:3000/trpc", | ||
headers: () => { | ||
return { | ||
Authorization: token ? `Bearer ${token}` : undefined, | ||
}; | ||
}, | ||
}), | ||
], | ||
transformer: superjson, | ||
}); | ||
} | ||
|
||
export async function createUser() { | ||
return prisma.user.create({ | ||
data: { | ||
name: faker.person.fullName(), | ||
email: faker.internet.email(), | ||
passwordHash: | ||
"SaVNC9ubXV8BHykB2wAD0mhxPwh/W7O7Rz+qRy/PeV+GeeakLzkv2TSghPQvLTe07b7TqxdsRUt39lC3RaaWmhORkVS9UbtEIh9dzvcbj9VzHA0ex0k97nv0lE56Jh6D6M5Laxe2BrkpiUibP3yCDCk75vCHtLGTZVjqtabTGheIs/QwiD72C7H+bK4QSL2RYSOEbB0wysNAC5nF8r1m36FB/DS5wEixOWiQH470H1s9yHODAALNag9Lom+It4P3cMSSa83mxPNvFOniEpuDDcI5W/Oxef/XiA3EhMLL8n4+CSV1Z891g65U7j7RIKSCjK1LbCvQ5JuS/jZCErNBW9472TXdGKGeYY6RTDgSBzqISyxlMCSRBsNjToWHJyPEyEbt0BTSjTkliB+0wSQpdzUiDDiJNrLVimAriH/AcU/eFvpU5YyyY1coY8Kc80LxKxP/p881Q0DABCmaRcDH+/1iEz3SoWNvSsw/Xq8u9LcgKCjccDoD8tKBDkMijS7TBPu9zJd2nUqblPO+KTGz7hVqh/u0VQ+xEdvRQuKSc+4OnUtQRVCAFQGB99hfXfQvffeGosNy3BABEuZkobaUgs8m8RTaRFGqy8qk6BYw1bk5I5KjjmA8GNOtNHlKQ+1EZO83pIKbG61Jfm93FJ6CsWji9fXsxaBsv+JNBhRgmUw=", | ||
passwordSalt: | ||
"dM4YXu5N5XY4c0LXnf30vtshh7dgsBYZ/5pZockgcJofPkWhMOplVAoWKhyqODZhO3mSUBqMqo3kXC2+7fOMt1NFB0Q1iRcJ4zaqAqdTenyjXu7rJ8WpgR1qnTcnpP8g/frQ+sk8Kcv49OC84R3v+FD8RrGm0rz8dDt7m7c/+Rw=", | ||
passwordVersion: 2, | ||
}, | ||
}); | ||
} | ||
|
||
export const createSession = (userId: string) => { | ||
const today = new Date(); | ||
const tomorrow = new Date(); | ||
tomorrow.setDate(today.getDate() + 1); | ||
|
||
return prisma.session.create({ | ||
data: { | ||
userId, | ||
token: faker.string.alphanumeric(40), | ||
type: "user", | ||
expires: tomorrow, | ||
}, | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "./dist" | ||
"outDir": "./dist", | ||
"allowJs": true, | ||
"module": "commonjs" | ||
}, | ||
"include": ["src/**/*.ts"] | ||
} |
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,14 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.ts" | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥