-
Notifications
You must be signed in to change notification settings - Fork 5
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 #28 from yurenju/feat/e2e-server-2
Feat/e2e server 2
- Loading branch information
Showing
9 changed files
with
178 additions
and
53 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Identity } from '@semaphore-protocol/identity'; | ||
import request from 'supertest'; | ||
import { MongoMemoryServer } from 'mongodb-memory-server'; | ||
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; | ||
import { | ||
generatePayload, | ||
getDomain, | ||
setupMongoDb, | ||
setupTestApplication, | ||
} from '../../tests/helper'; | ||
|
||
describe('UsersModule', () => { | ||
let app: INestApplication; | ||
let mongod: MongoMemoryServer; | ||
|
||
beforeEach(async () => { | ||
mongod = await setupMongoDb(); | ||
app = await setupTestApplication(mongod.getUri()); | ||
}); | ||
|
||
afterEach(async () => { | ||
await mongod.stop(); | ||
await app.close(); | ||
}); | ||
|
||
it('should get an array of semaphore commitments', async () => { | ||
const server = app.getHttpServer(); | ||
const domain = getDomain(server); | ||
|
||
const res = await request(server) | ||
.post('/api/auth/national/register') | ||
.send({ username: 'username', password: 'password' }); | ||
|
||
const { id, token } = res.body; | ||
|
||
const challengeRes = await request(server) | ||
.post('/api/auth/ethereum/challenge') | ||
.set('Authorization', `Bearer ${token}`) | ||
.expect(201); | ||
|
||
const privateKey = generatePrivateKey(); | ||
const account = privateKeyToAccount(privateKey); | ||
const payload = await generatePayload( | ||
id, | ||
domain, | ||
account, | ||
challengeRes.body.value | ||
); | ||
|
||
const identity = new Identity(); | ||
const commitment = identity.commitment.toString(); | ||
|
||
await request(server) | ||
.post('/api/auth/ethereum/login') | ||
.send(payload) | ||
.set('Authorization', `Bearer ${token}`); | ||
|
||
await request(server) | ||
.put('/api/auth/semaphore') | ||
.send({ id, commitment }) | ||
.set('Authorization', `Bearer ${token}`); | ||
|
||
await request(server) | ||
.get('/api/users/commitments') | ||
.expect((res) => { | ||
expect(res.body).toEqual([commitment]); | ||
}); | ||
}); | ||
}); |
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