From 3bbfd9037640ccf721152cae8b8af02fd8ae011b Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Mon, 15 Jan 2024 17:08:57 -0800 Subject: [PATCH] Add tokens tests --- routes/tokens.js | 6 ++++++ routes/tokens.test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 routes/tokens.test.js diff --git a/routes/tokens.js b/routes/tokens.js index f171b9a..0eba4a7 100644 --- a/routes/tokens.js +++ b/routes/tokens.js @@ -30,6 +30,8 @@ const { * responses: * 200: * description: Token created successfully + * 400: + * description: Invalid token */ tokensRoutes.route("/token/add").post(addToken); /** @@ -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); /** @@ -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") diff --git a/routes/tokens.test.js b/routes/tokens.test.js new file mode 100644 index 0000000..7db8c82 --- /dev/null +++ b/routes/tokens.test.js @@ -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/); + }); +});