-
Notifications
You must be signed in to change notification settings - Fork 2
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
Nikola Mlinaric
committed
Feb 24, 2020
1 parent
8197bdd
commit ee1c281
Showing
1 changed file
with
146 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import {expect} from "chai"; | ||
import {describe} from "mocha"; | ||
import request from "supertest"; | ||
import logger from "../../../../src/Services/Logger"; | ||
import {app} from "../../index.test"; | ||
import database from "../../../../src/Services/Database"; | ||
import config from "../../../../src/Config/Config"; | ||
import * as jwt from "jsonwebtoken"; | ||
import * as bcrypt from "bcryptjs"; | ||
import {User} from "../../../../src/Models/User"; | ||
import {Node} from "../../../../src/Models/Node"; | ||
import {NodeUptime} from "../../../../src/Models/NodeUptime"; | ||
|
||
describe("Node uptime controller - fetch uptime test", async () => { | ||
|
||
before(async function () { | ||
const password = bcrypt.hashSync('password', 10); | ||
// eslint-disable-next-line no-console | ||
console.log("Before NodeUptime e2e test"); | ||
// eslint-disable-next-line | ||
await User.create({id: 100, email: 'test@test.com', hash_password: `${password}`}) | ||
await Node.create({ | ||
id: 5, | ||
token: 'token111', | ||
url: 'url111', | ||
address: 'address111', | ||
userId: 100 | ||
}); | ||
await NodeUptime.create({ | ||
id: 10, | ||
isWorking: true, | ||
nodeId: 5 | ||
}); | ||
}); | ||
|
||
after(async () => { | ||
await database.sequelize.sync({force: true}); | ||
// eslint-disable-next-line no-console | ||
console.log("After NodeUptime e2e test") | ||
}); | ||
|
||
it("Should return a filtered array (by month) of uptime for a certain node", (done) => { | ||
const token = jwt.sign({id: 100}, config.jwtKey, {expiresIn: '24h'}) | ||
|
||
try { | ||
request(app.server) | ||
.get("/api/user/node/uptime/5?filter=month") | ||
.set('Authorization', token) | ||
.send({ | ||
params: { | ||
nodeId: 5, | ||
}, | ||
query: { | ||
filter: 'month' | ||
} | ||
}) | ||
.expect(200) | ||
.end((err, res) => { | ||
expect(res).to.exist; | ||
expect(err).to.not.exist; | ||
expect(res.body).to.be.a('array').that.is.not.empty; | ||
done(); | ||
}); | ||
|
||
} catch (err) { | ||
logger.error('Unexpected error occured: ${err.message}'); | ||
expect.fail(err); | ||
done(); | ||
} | ||
}); | ||
|
||
it("Should fail with filter must be one of [day, week, month, year] error", (done) => { | ||
const token = jwt.sign({id: 100}, config.jwtKey, {expiresIn: '24h'}) | ||
|
||
try { | ||
request(app.server) | ||
.get("/api/user/node/uptime/5?filter=quarter") | ||
.set('Authorization', token) | ||
.send({ | ||
params: { | ||
nodeId: 5, | ||
}, | ||
query: { | ||
filter: 'quarter' | ||
} | ||
}) | ||
.expect(200) | ||
.end((err, res) => { | ||
expect(res).to.exist; | ||
expect(err).to.exist; | ||
expect(res.body).to.deep.include( | ||
{ | ||
type: "query", | ||
"errors": [ | ||
{ | ||
"message": "\"filter\" must be one of [day, week, month, year]", | ||
"name": "filter" | ||
} | ||
] | ||
}); | ||
done(); | ||
}); | ||
|
||
} catch (err) { | ||
logger.error('Unexpected error occured: ${err.message}'); | ||
expect.fail(err); | ||
done(); | ||
} | ||
}); | ||
|
||
it("Should fail with filter is required error", (done) => { | ||
const token = jwt.sign({id: 100}, config.jwtKey, {expiresIn: '24h'}) | ||
|
||
try { | ||
request(app.server) | ||
.get("/api/user/node/uptime/5") | ||
.set('Authorization', token) | ||
.send({ | ||
params: { | ||
nodeId: 5, | ||
} | ||
}) | ||
.expect(200) | ||
.end((err, res) => { | ||
expect(res).to.exist; | ||
expect(err).to.exist; | ||
expect(res.body).to.deep.include( | ||
{ | ||
type: "query", | ||
"errors": [ | ||
{ | ||
"message": "\"filter\" is required", | ||
"name": "filter" | ||
} | ||
] | ||
}); | ||
done(); | ||
}); | ||
|
||
} catch (err) { | ||
logger.error('Unexpected error occured: ${err.message}'); | ||
expect.fail(err); | ||
done(); | ||
} | ||
}); | ||
}); |