-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.test.js
120 lines (94 loc) · 4.15 KB
/
api.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import request from 'supertest';
import app from './api.js'; // Assuming the API module is exported as 'app'
// Endpoint for Proof of Humanity
describe('Root API Endpoints', () => {
it('GET / should respond with 200 and a message', async () => {
const response = await request(app).get('/');
expect(response.status).toBe(200);
expect(response.body).toEqual({ message: 'Proof of Humanity' });
});
});
// Endpoint for generating a proof using Worldcoin validator
describe('Worldcoin API Endpoints', () => {
it('POST /worldcoin/proof should respond with a valid proof on successful validation', async () => {
const data = "0x1234567890abcdef";
const worldcoinProof = "This is a test Worldcoin proof";
const response = await request(app)
.post('/worldcoin/proof')
.send({ data, worldcoinProof });
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('proof');
});
it('POST /worldcoin/proof should respond with an error on failed validation', async () => {
const data = "This is an invalid data should cause an error";
const worldcoinProof = "This is a test Worldcoin proof";
const response = await request(app)
.post('/worldcoin/proof')
.send({ data, worldcoinProof });
expect(response.status).toBe(500);
expect(response.body).toHaveProperty('error');
});
});
// Endpoint for generating a proof using Humangram validator
describe('Humangram API Endpoints', () => {
it('POST /humangram/proof should respond with a valid proof on successful validation', async () => {
const data = "0x1234567890abcdef";
const worldcoinProof = "This is a test Worldcoin proof";
const response = await request(app)
.post('/humangram/proof')
.send({ data, worldcoinProof });
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('proof');
});
it('POST /humangram/proof should respond with an error on failed validation', async () => {
const data = "This is an invalid data should cause an error";
const worldcoinProof = "This is a test Worldcoin proof";
const response = await request(app)
.post('/humangram/proof')
.send({ data, worldcoinProof });
expect(response.status).toBe(500);
expect(response.body).toHaveProperty('error');
});
});
// Endpoint for generating a proof using Biometrics validator
describe('Biometrics API Endpoints', () => {
it('POST /biometrics/proof should respond with a valid proof on successful validation', async () => {
const data = "0x1234567890abcdef";
const token = "This is a test Worldcoin proof";
const response = await request(app)
.post('/biometrics/proof')
.send({ data, token });
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('proof');
});
it('POST /biometrics/proof should respond with an error on failed validation', async () => {
const data = "This is an invalid data should cause an error";
const token = "This is a test Worldcoin proof";
const response = await request(app)
.post('/biometrics/proof')
.send({ data, token });
expect(response.status).toBe(500);
expect(response.body).toHaveProperty('error');
});
});
// Endpoint for generating a proof using Ledger validator
describe('Ledger API Endpoints', () => {
it('POST /ledger/proof should respond with a valid proof on successful validation', async () => {
const data = "0x1234567890abcdef";
const worldcoinProof = "This is a test Worldcoin proof";
const response = await request(app)
.post('/ledger/proof')
.send({ data, worldcoinProof });
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('proof');
});
it('POST /ledger/proof should respond with an error on failed validation', async () => {
const data = "This is an invalid data should cause an error";
const worldcoinProof = "This is a test Worldcoin proof";
const response = await request(app)
.post('/ledger/proof')
.send({ data, worldcoinProof });
expect(response.status).toBe(500);
expect(response.body).toHaveProperty('error');
});
});