Skip to content

Commit

Permalink
Add tokens tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benefacto committed Jan 16, 2024
1 parent 64d931a commit 3bbfd90
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions routes/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const {
* responses:
* 200:
* description: Token created successfully
* 400:
* description: Invalid token
*/
tokensRoutes.route("/token/add").post(addToken);
/**
Expand All @@ -48,6 +50,8 @@ tokensRoutes.route("/token/add").post(addToken);
* responses:
* 200:
* description: Details of the token
* 400:
* description: Invalid token id
*/
tokensRoutes.route("/token/:id").get(getTokenById);
/**
Expand Down Expand Up @@ -78,6 +82,8 @@ tokensRoutes.route("/token/:id").get(getTokenById);
* responses:
* 200:
* description: Voting power information for the token
* 400:
* description: Invalid token location
*/
tokensRoutes
.route("/network/:network/token/:address/token-id/:tokenID/voting-power")
Expand Down
29 changes: 29 additions & 0 deletions routes/tokens.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const request = require("supertest");
const express = require("express");
const tokensRoutes = require("./tokens");

const app = express();
app.use(express.json());
app.use("/", tokensRoutes);
const id = 123;

describe("Tokens Routes", () => {
it("should add a token that's invalid", async () => {
await request(app)
.post(`/token/add`)
.send("")
.expect(400)
});
it("should not get a token with an invalid id", async () => {
await request(app)
.get(`/token/${id}`)
.expect(400)
.expect("Content-Type", /json/);
});
it("should not a find voting power for a token with an invalid location", async () => {
await request(app)
.get(`/network/${id}/token/${id}/token-id/${id}/voting-power`)
.expect(400)
.expect("Content-Type", /json/);
});
});

0 comments on commit 3bbfd90

Please sign in to comment.