Skip to content

Commit

Permalink
fix jest open handles
Browse files Browse the repository at this point in the history
Signed-off-by: F-Node-Karlsruhe <christian.fries@eecc.de>
  • Loading branch information
F-Node-Karlsruhe committed Oct 10, 2023
1 parent 547d624 commit d684a19
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
23 changes: 14 additions & 9 deletions api/__tests__/credential.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import request from "supertest";

import app from "../src/index";
import server from "../src/index";

afterAll(done => {
server.close();
done();
});

const revoked2020Credential: any = {
"@context": [
Expand Down Expand Up @@ -192,14 +197,14 @@ const manipulatedCredential = Object.assign({ ...GS1LicenceCredential }, { issua
describe("Verifier API Test for Credentials", () => {

test("Verify vc by id", async () => {
const res = await request(app).get("/api/verifier/vc/https%253A%252F%252Fid.gs1.org%252Fvc%252Flicence%252Fgs1_prefix%252F05");
const res = await request(server).get("/api/verifier/vc/https%253A%252F%252Fid.gs1.org%252Fvc%252Flicence%252Fgs1_prefix%252F05");
expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty('verified');
expect(res.body.verified).toBe(true);
});

test("Verify single credential", async () => {
const res = await request(app).post("/api/verifier").send([GS1LicenceCredential]);
const res = await request(server).post("/api/verifier").send([GS1LicenceCredential]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(true);
Expand All @@ -209,14 +214,14 @@ describe("Verifier API Test for Credentials", () => {
* Test selective disclosure DataIntegrityProof credential
*/
test("Verify single DataIntegrityProof credential", async () => {
const res = await request(app).post("/api/verifier").send([SDCredential]);
const res = await request(server).post("/api/verifier").send([SDCredential]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(true);
});

test("Verify multiple credentials", async () => {
const res = await request(app).post("/api/verifier").send([GS1LicenceCredential, GS1LicenceCredential]);
const res = await request(server).post("/api/verifier").send([GS1LicenceCredential, GS1LicenceCredential]);
expect(res.statusCode).toEqual(200);
res.body.forEach((el: any) => {
expect(el).toHaveProperty('verified');
Expand All @@ -228,7 +233,7 @@ describe("Verifier API Test for Credentials", () => {
* Test StatusList2020 revoked credential
*/
test("Verify revoked credential", async () => {
const res = await request(app).post("/api/verifier").send([revoked2020Credential]);
const res = await request(server).post("/api/verifier").send([revoked2020Credential]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(false);
Expand All @@ -240,7 +245,7 @@ describe("Verifier API Test for Credentials", () => {
* Test StatusList2021 revoked credential
*/
test("Verify revoked credential", async () => {
const res = await request(app).post("/api/verifier").send([revoked2021Credential]);
const res = await request(server).post("/api/verifier").send([revoked2021Credential]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(false);
Expand All @@ -252,7 +257,7 @@ describe("Verifier API Test for Credentials", () => {
* Test StatusList2021 suspended credential
*/
test("Verify suspended credential", async () => {
const res = await request(app).post("/api/verifier").send([suspended2021Credential]);
const res = await request(server).post("/api/verifier").send([suspended2021Credential]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(false);
Expand All @@ -261,7 +266,7 @@ describe("Verifier API Test for Credentials", () => {
});

test("Falsify single credential", async () => {
const res = await request(app).post("/api/verifier").send([manipulatedCredential]);
const res = await request(server).post("/api/verifier").send([manipulatedCredential]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(false);
Expand Down
15 changes: 10 additions & 5 deletions api/__tests__/presentation.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import request from "supertest";

import app from "../src/index";
import server from "../src/index";

afterAll(done => {
server.close();
done();
});

const multiPresentation: any = {
"@context": [
Expand Down Expand Up @@ -198,7 +203,7 @@ const statusPresentation: any = {
describe("Verifier API Test for Presentations", () => {

test("Verify presentation with status", async () => {
const res = await request(app).post("/api/verifier").send([statusPresentation]);
const res = await request(server).post("/api/verifier").send([statusPresentation]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(true);
Expand All @@ -210,7 +215,7 @@ describe("Verifier API Test for Presentations", () => {
});

test("Verify single presentation with challenge", async () => {
const res = await request(app).post("/api/verifier").query({ challenge: '12345' }).send([multiPresentation]);
const res = await request(server).post("/api/verifier").query({ challenge: '12345' }).send([multiPresentation]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(true);
Expand All @@ -222,7 +227,7 @@ describe("Verifier API Test for Presentations", () => {
});

test("Verify single presentation with challenge & domain", async () => {
const res = await request(app).post("/api/verifier").query({ challenge: '12345', domain: 'ssi.eecc.de/verifier' }).send([domainPresentation]);
const res = await request(server).post("/api/verifier").query({ challenge: '12345', domain: 'ssi.eecc.de/verifier' }).send([domainPresentation]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(true);
Expand All @@ -234,7 +239,7 @@ describe("Verifier API Test for Presentations", () => {
});

test("Falsify single presentation with wrong challenge", async () => {
const res = await request(app).post("/api/verifier").query({ challenge: 'falseChallenge', domain: 'ssi.eecc.de/verifier' }).send([domainPresentation]);
const res = await request(server).post("/api/verifier").query({ challenge: 'falseChallenge', domain: 'ssi.eecc.de/verifier' }).send([domainPresentation]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(false);
Expand Down
1 change: 1 addition & 0 deletions api/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ module.exports = {
},
],
},
testTimeout: 15000
};
12 changes: 6 additions & 6 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ app.use('/api/verifier', verifyRouter);

const port = process.env.PORT ? Number.parseInt(process.env.PORT) : 3000

if (process.env.NODE_ENV !== 'test') {
const server = app.listen(port, async () => {
console.log(`Started API Server on port ${port}`);
});
}

export default app;
const server = app.listen(port, async () => {
console.log(`Started API Server on port ${port}`);
});


export default server;

0 comments on commit d684a19

Please sign in to comment.