-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
module.exports = async () => { | ||
const mongoServer = await MongoMemoryServer.create(); | ||
process.env.MONGO_URI = mongoServer.getUri(); | ||
process.env.TEST_MONGO_URI = mongoServer.getUri(); | ||
|
||
// Store server information in a temporary file | ||
const tempFilePath = path.join(__dirname, 'mongoServerInfo.json'); | ||
fs.writeFileSync(tempFilePath, JSON.stringify({ uri: mongoServer.getUri(), instanceId: mongoServer.instanceInfo?.instanceId })); | ||
// Store the MongoMemoryServer instance in a global variable | ||
global.__MONGOSERVER__ = mongoServer; | ||
}; |
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 |
---|---|---|
@@ -1,18 +1,5 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
|
||
module.exports = async () => { | ||
// Read the server information from the temporary file | ||
const tempFilePath = path.join(__dirname, 'mongoServerInfo.json'); | ||
if (fs.existsSync(tempFilePath)) { | ||
const serverInfo = JSON.parse(fs.readFileSync(tempFilePath, 'utf8')); | ||
if (serverInfo && serverInfo.instanceId) { | ||
// Stop the server | ||
await MongoMemoryServer.stop({ instanceId: serverInfo.instanceId }); | ||
} | ||
|
||
// Remove the temporary file | ||
fs.unlinkSync(tempFilePath); | ||
if (global.__MONGOSERVER__) { | ||
await global.__MONGOSERVER__.stop(); | ||
} | ||
}; | ||
}; |
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,57 @@ | ||
const request = require("supertest"); | ||
const express = require("express"); | ||
const daosRoutes = require("../routes/daos"); | ||
|
||
const app = express(); | ||
app.use(express.json()); | ||
app.use("/", daosRoutes); | ||
const id = 123; | ||
|
||
describe("Daos Routes", () => { | ||
it("should not join a dao with an invalid signature payload", async () => { | ||
await request(app) | ||
.post(`/daos/join`) | ||
.send({daoId: `${id}`}) | ||
.set('Accept', 'application/json') | ||
.expect(500) | ||
}); | ||
it("should not add a dao with an invalid signature payload", async () => { | ||
await request(app) | ||
.post(`/dao/add`) | ||
.send({daoDetails: {}}) | ||
.set('Accept', 'application/json') | ||
.expect(500) | ||
}); | ||
it("should not return a list of daos with an invalid signature payload", async () => { | ||
await request(app) | ||
.post(`/daos`) | ||
.send('') | ||
.expect(400) | ||
.expect("Content-Type", /json/) | ||
}); | ||
it("should not return a dao contract with an invalid signature payload", async () => { | ||
await request(app) | ||
.post(`/daos/contracts/${id}`) | ||
.send('') | ||
.expect(400) | ||
.expect("Content-Type", /json/) | ||
}); | ||
it("should not find a dao with an invalid ID", async () => { | ||
await request(app) | ||
.get(`/daos/${id}`) | ||
.expect(400) | ||
.expect("Content-Type", /json/) | ||
}); | ||
it("should not add a new field to the DAO collection with an invalid signature payload", async () => { | ||
await request(app) | ||
.get(`/daos/create/voting`) | ||
.expect(400) | ||
.expect("Content-Type", /json/) | ||
}); | ||
it("should not update total voting addresses count for a dao with an invalid ID", async () => { | ||
await request(app) | ||
.get(`/daos/${id}`) | ||
.expect(400) | ||
.expect("Content-Type", /json/) | ||
}); | ||
}); |