This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from technologiestiftung/chore/prod-deps
- Loading branch information
Showing
11 changed files
with
937 additions
and
1,007 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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,87 +1,90 @@ | ||
/* eslint-disable jest/no-commented-out-tests */ | ||
/* eslint-disable jest/no-disabled-tests */ | ||
/* eslint-disable jest/no-hooks */ | ||
import nock from "nock"; | ||
// import nock from "nock"; | ||
// import * as supabase from "@supabase/supabase-js"; | ||
import { | ||
authtokenEndpoint, | ||
buildServerOpts, | ||
closePool, | ||
connectPool, | ||
deleteUser, | ||
signupUser, | ||
supabaseUrl, | ||
truncateTables, | ||
} from "../../__test-utils"; | ||
// import { | ||
// // authtokenEndpoint, | ||
// // buildServerOpts, | ||
// closePool, | ||
// connectPool, | ||
// // deleteUser, | ||
// // signupUser, | ||
// // supabaseUrl, | ||
// truncateTables, | ||
// } from "../../__test-utils"; | ||
|
||
import { buildServer } from "../server"; | ||
// import { buildServer } from "../server"; | ||
// import { PostgrestError } from "@supabase/supabase-js"; | ||
// jest.mock("@supabase/supabase-js", () => ({ | ||
// createClient: jest.fn(), | ||
// })); | ||
describe("error handling", () => { | ||
beforeAll(async () => { | ||
await connectPool(); | ||
}); | ||
beforeEach(async () => { | ||
await truncateTables(); | ||
}); | ||
// eslint-disable-next-line jest/no-hooks | ||
afterAll(async () => { | ||
await truncateTables(); | ||
await closePool(); | ||
}); | ||
test("should throw an error in GET due to returned postgres error", async () => { | ||
const server = buildServer(buildServerOpts); | ||
const user = await signupUser(); | ||
|
||
const logSpy = jest.spyOn(server.log, "error"); | ||
// const httpErrorsSpy = jest.spyOn(server.httpErrors, "internalServerError"); | ||
const scope = nock(supabaseUrl) | ||
.get("/rest/v1/auth_tokens") | ||
.query(true) | ||
.reply(500); | ||
|
||
const res = await server.inject({ | ||
method: "GET", | ||
url: authtokenEndpoint, | ||
headers: { authorization: `Bearer ${user.token}` }, | ||
}); | ||
expect(res.statusCode).toBe(500); | ||
expect(logSpy).toHaveBeenCalledTimes(1); | ||
scope.done(); | ||
nock.cleanAll(); | ||
nock.enableNetConnect(); | ||
jest.resetAllMocks(); | ||
// expect(httpErrorsSpy).toHaveBeenCalledTimes(1); | ||
await deleteUser(user.token); | ||
}); | ||
describe("error handling for auth tokens", () => { | ||
// beforeAll(async () => { | ||
// await connectPool(); | ||
// }); | ||
// beforeEach(async () => { | ||
// await truncateTables(); | ||
// }); | ||
// // eslint-disable-next-line jest/no-hooks | ||
// afterAll(async () => { | ||
// await truncateTables(); | ||
// await closePool(); | ||
// }); | ||
// TODO: Create new test for auth tokens errors, since nock did interfear with all other tests | ||
test.todo("should throw an error in GET due to returned postgres error - use nock",); | ||
}); | ||
//async () => { | ||
// const server = buildServer(buildServerOpts); | ||
// const user = await signupUser(); | ||
|
||
// test.only("should mock supabase and return error", async () => { | ||
// const err: PostgrestError = { | ||
// code: "500", | ||
// message: "string", | ||
// details: "string", | ||
// hint: "string", | ||
// }; | ||
// const postgrestResponse: any = { | ||
// from: jest.fn().mockRejectedValue({ error: err }), | ||
// select: jest.fn().mockRejectedValue({ error: err }), | ||
// }; | ||
// //@ts-ignore | ||
// supabase.createClient.mockImplementation(() => { | ||
// return postgrestResponse; | ||
// }); | ||
// const server = buildServer(buildServerOpts); | ||
// const user = await signupUser(); | ||
// const res = await server.inject({ | ||
// method: "GET", | ||
// url: authtokenEndpoint, | ||
// headers: { authorization: `Bearer ${user.token}` }, | ||
// const logSpy = jest.spyOn(server.log, "error"); | ||
// // const httpErrorsSpy = jest.spyOn(server.httpErrors, "internalServerError"); | ||
// const scope = nock(supabaseUrl) | ||
// .get("/rest/v1/auth_tokens") | ||
// .query(true) | ||
// .reply(500); | ||
|
||
// const res = await server.inject({ | ||
// method: "GET", | ||
// url: authtokenEndpoint, | ||
// headers: { authorization: `Bearer ${user.token}` }, | ||
// }); | ||
// expect(res.statusCode).toBe(500); | ||
// expect(logSpy).toHaveBeenCalledTimes(1); | ||
// scope.done(); | ||
// nock.cleanAll(); | ||
// nock.enableNetConnect(); | ||
// jest.resetAllMocks(); | ||
// // expect(httpErrorsSpy).toHaveBeenCalledTimes(1); | ||
// await deleteUser(user.token); | ||
// }); | ||
// expect(res.statusCode).toBe(500); | ||
// expect(supabase.createClient).toHaveBeenCalledTimes(1); | ||
// expect(postgrestResponse.select).toHaveBeenCalledTimes(1); | ||
// await deleteUser(user.token); | ||
// }); | ||
|
||
// // test.only("should mock supabase and return error", async () => { | ||
// // const err: PostgrestError = { | ||
// // code: "500", | ||
// // message: "string", | ||
// // details: "string", | ||
// // hint: "string", | ||
// // }; | ||
// // const postgrestResponse: any = { | ||
// // from: jest.fn().mockRejectedValue({ error: err }), | ||
// // select: jest.fn().mockRejectedValue({ error: err }), | ||
// // }; | ||
// // //@ts-ignore | ||
// // supabase.createClient.mockImplementation(() => { | ||
// // return postgrestResponse; | ||
// // }); | ||
// // const server = buildServer(buildServerOpts); | ||
// // const user = await signupUser(); | ||
// // const res = await server.inject({ | ||
// // method: "GET", | ||
// // url: authtokenEndpoint, | ||
// // headers: { authorization: `Bearer ${user.token}` }, | ||
// // }); | ||
// // expect(res.statusCode).toBe(500); | ||
// // expect(supabase.createClient).toHaveBeenCalledTimes(1); | ||
// // expect(postgrestResponse.select).toHaveBeenCalledTimes(1); | ||
// // await deleteUser(user.token); | ||
// // }); |
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
Oops, something went wrong.