feat: 100% code-coverage, add coverage to gitignore

pull/9078/head
Agusti Fernandez Pardo 2022-03-25 02:07:51 +01:00
parent f6371c3b75
commit a71039328f
3 changed files with 95 additions and 73 deletions

73
.gitignore vendored
View File

@ -1,6 +1,71 @@
dist # .env file
node_modules/
.env .env
# dependencies
node_modules
.pnp
.pnp.js
# testing
coverage
/test-results/
playwright/videos
playwright/screenshots
playwright/artifacts
playwright/results
playwright/reports/*
# next.js
.next/ .next/
.turbo/ out/
*.tsbuildinfo build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
.env.*
!.env.example
# vercel
.vercel
# Webstorm
.idea
### VisualStudioCode template
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Typescript
tsconfig.tsbuildinfo
# turbo
.turbo
# Prisma-Zod
packages/prisma/zod/*.ts
# Builds
dist
# Linting
lint-results

View File

@ -4,11 +4,6 @@ import prisma from "@calcom/prisma";
import handleEvent from "../../../pages/api/event-types/[id]"; import handleEvent from "../../../pages/api/event-types/[id]";
afterAll((done) => {
prisma.$disconnect().then();
done();
});
describe("GET /api/event-types/[id] with valid id as string returns an event-type", () => { describe("GET /api/event-types/[id] with valid id as string returns an event-type", () => {
it("returns a message with the specified events", async () => { it("returns a message with the specified events", async () => {
const { req, res } = createMocks({ const { req, res } = createMocks({
@ -79,3 +74,25 @@ describe("POST /api/event-types/[id] fails, only GET allowed", () => {
expect(JSON.parse(res._getData())).toStrictEqual({ error: "Only GET Method allowed" }); expect(JSON.parse(res._getData())).toStrictEqual({ error: "Only GET Method allowed" });
}); });
}); });
describe("PATCH /api/event-types/[id]/edit with valid id and body updates an event-type", () => {
it("returns a message with the specified events", async () => {
const { req, res } = createMocks({
method: "PATCH",
query: {
id: "1",
},
});
const event = await prisma.eventType.findUnique({ where: { id: 1 } });
await handleEvent(req, res);
expect(res._getStatusCode()).toBe(200);
if (event) event.title = "Updated title";
expect(JSON.parse(res._getData())).toStrictEqual({ data: event });
});
});
afterAll((done) => {
prisma.$disconnect().then();
done();
});

View File

@ -3,16 +3,7 @@
* https://jestjs.io/docs/en/configuration.html * https://jestjs.io/docs/en/configuration.html
*/ */
export default { const config = {
// All imported modules in your tests should be mocked automatically
// automock: false,
// Stop running tests after `n` failures
// bail: 0,
// The directory where Jest should store its cached dependency information
// cacheDirectory: "/private/var/folders/fl/sw088bcs0dx4zyy0f_ghzvwc0000gn/T/jest_dx",
// Automatically clear mock calls and instances between every test // Automatically clear mock calls and instances between every test
clearMocks: true, clearMocks: true,
@ -24,6 +15,7 @@ export default {
// The directory where Jest should output its coverage files // The directory where Jest should output its coverage files
coverageDirectory: "coverage", coverageDirectory: "coverage",
collectCoverage: true,
// An array of regexp pattern strings used to skip coverage collection // An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [ // coveragePathIgnorePatterns: [
@ -133,64 +125,12 @@ export default {
// setupFilesAfterEnv: [], // setupFilesAfterEnv: [],
// The number of seconds after which a test is considered as slow and reported as such in the results. // The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5, slowTestThreshold: 1,
// A list of paths to snapshot serializer modules Jest should use for snapshot testing // A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [], // snapshotSerializers: [],
// The test environment that will be used for testing // The test environment that will be used for testing
testEnvironment: "node", testEnvironment: "node",
// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
// Adds a location field to test results
// testLocationInResults: false,
// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "/node_modules/"
// ],
// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],
// This option allows the use of a custom results processor
// testResultsProcessor: undefined,
// This option allows use of a custom test runner
// testRunner: "jasmine2",
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
// testURL: "http://localhost",
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
// timers: "real",
// A map from regular expressions to paths to transformers
// transform: undefined,
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "/node_modules/",
// "\\.pnp\\.[^\\/]+$"
// ],
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
// Indicates whether each individual test should be reported during the run
// verbose: undefined,
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],
// Whether to use watchman for file crawling
// watchman: true,
}; };
export default config;