-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing completed for responder endpoints #75
Open
matthewleemle
wants to merge
10
commits into
master
Choose a base branch
from
testing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ff81ceb
first commit
matthewleemle 0370753
Merge branch 'master' into testing
matthewleemle 1bad0c1
change directory
matthewleemle adfa4d0
json send bug
matthewleemle e071d63
Change string interpolation
Asiapenguin bdf9246
adding responder_count test
matthewleemle fbea08c
Merge branch 'master' into testing
matthewleemle 50de6d0
added changes
matthewleemle f9c242e
added changes
matthewleemle 94f8f2d
added changes
matthewleemle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import chai from "chai"; | ||
import chaiHttp from "chai-http"; | ||
import app from "../server"; | ||
var database = require("../database"); | ||
var db = database.getdb(); | ||
import metrics from "../database/postgres" | ||
|
||
var metricdb = metrics.getMetrics(); | ||
var UserModel = require("../models/user").model; | ||
|
||
chai.use(chaiHttp); | ||
chai.should(); | ||
|
@@ -18,8 +20,8 @@ describe("Sign up and Login", () => { | |
it("should sign up user", (done) => { | ||
chai.request(app) | ||
.post("/signup") | ||
.send({ | ||
username: username, | ||
.send({ | ||
username: username, | ||
email: email, | ||
password: plainTextPassword, | ||
phone: phone, | ||
|
@@ -55,12 +57,143 @@ describe("Sign up and Login", () => { | |
}) | ||
}) | ||
|
||
|
||
after(async () => { | ||
try { | ||
await db.collection("users").remove({ username: username }) | ||
await UserModel.deleteMany({username:username}); | ||
await metricdb('users') | ||
.whereIn('username', [username]) | ||
.del() | ||
console.log("Processed after()"); | ||
} catch (err) { | ||
console.log("Failed to delete created user"); | ||
console.log(err) | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
describe("Create 2 accounts and tests for search and responding",() => { | ||
|
||
var token = ""; | ||
var userId = ""; | ||
|
||
it("should sign up user A", (done) => { | ||
chai.request(app) | ||
.post("/signup") | ||
.send({ | ||
username: "Ausername", | ||
email: "[email protected]", | ||
password: "Auserpassword", | ||
phone: "12345678" | ||
}) | ||
.end((err, res) => { | ||
res.should.have.status(200); | ||
res.body.should.be.a("object"); | ||
done(); | ||
}) | ||
}) | ||
|
||
it("should sign up user B", (done) => { | ||
chai.request(app) | ||
.post("/signup") | ||
.send({ | ||
username: "Busername", | ||
email: "[email protected]", | ||
password: "Buserpassword", | ||
phone: "988655332" | ||
}) | ||
.end((err, res) => { | ||
res.should.have.status(200); | ||
res.body.should.be.a("object"); | ||
done(); | ||
}) | ||
}) | ||
|
||
|
||
it("should authenticate A with correct credentials", (done) => { | ||
chai.request(app) | ||
.post("/login") | ||
.send({ username: "Ausername", password: "Auserpassword" }) | ||
.end((err, res) => { | ||
res.should.have.status(200); | ||
res.body.should.be.a("object"); | ||
userId = res.body.id; | ||
token = res.body.token; | ||
done(); | ||
}) | ||
}) | ||
|
||
it("should authenticate B with correct credentials and turn it online", (done) => { | ||
chai.request(app) | ||
.post("/login") | ||
.send({ username: "Busername", password: "Buserpassword" }) | ||
.end((err, res) => { | ||
res.should.have.status(200); | ||
res.body.should.be.a("object"); | ||
done(); | ||
}) | ||
}) | ||
var users = []; | ||
var BuserID; | ||
|
||
it("should have B as one of the users being shown up", (done) =>{ | ||
chai.request(app) | ||
.get("/users/search") | ||
.set("Authorization", `Bearer ${token}`) | ||
.end((err,res)=> { | ||
res.should.have.status(200); | ||
console.log(res.body); | ||
res.body.forEach((user)=>{ | ||
users.push(user.username); | ||
if(user.username==="Busername") | ||
BuserID = user._id; | ||
}); | ||
users.should.include("Busername"); | ||
done(); | ||
}) | ||
}) | ||
|
||
it("should add B as a responder for user A", (done) =>{ | ||
let respondersToAddArr = [{id: BuserID}]; | ||
|
||
chai.request(app) | ||
.post(`/users/${userId}/responders`) | ||
.set("Authorization", `Bearer ${token}`) | ||
.send({respondersToAdd: respondersToAddArr}) | ||
.end((err, res) => { | ||
console.log(res.body); | ||
res.should.have.status(200); | ||
res.body.should.be.a("object"); | ||
done(); | ||
}) | ||
}) | ||
|
||
it("should have 1 responder count for user A", (done) => { | ||
chai.request(app) | ||
.get(`/users/${userId}/responders/count`) | ||
.set("Authorization", `Bearer ${token}`) | ||
.end((err, res) => { | ||
console.log(res.body); | ||
res.should.have.status(200); | ||
res.body.should.be.a("object"); | ||
console.log(res.body); | ||
done(); | ||
}) | ||
}) | ||
|
||
|
||
after(async () => { | ||
try { | ||
await UserModel.deleteMany({username: { $in: ["Busername","Ausername"]}}); | ||
await metricdb('users') | ||
.whereIn('username', ["Busername","Ausername"]) | ||
.del() | ||
console.log("Processed after()"); | ||
} catch (err) { | ||
console.log("Failed to delete created user"); | ||
console.log(err) | ||
} | ||
|
||
}) | ||
|
||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe this is not needed (try catch block)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was something I had during debugging, I'll take it away