-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:two-factor/two-factor into dev
- Loading branch information
Showing
1 changed file
with
62 additions
and
3 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 |
---|---|---|
@@ -1,3 +1,62 @@ | ||
describe('', () => { | ||
|
||
} | ||
const verify = require("../../../../functions/databases/postgres/verify"); | ||
|
||
describe("test for postgres", () => { | ||
class FakeClient { | ||
constructor() { | ||
this.pgConnect = function() { | ||
return new Promise((resolve, reject) => { | ||
resolve({ | ||
database: { | ||
query: function(query, values, callback) { | ||
return new Promise((resolve, reject) => { | ||
resolve({ | ||
rows: [ | ||
{ | ||
sid: "fakesid", | ||
phone: "1234" | ||
} | ||
] | ||
}); | ||
}); | ||
} | ||
}, | ||
done: function() { | ||
return null; | ||
} | ||
}); | ||
}); | ||
}; | ||
this.client = { | ||
verify: { | ||
services: function(sid) { | ||
return { | ||
verificationChecks: { | ||
create: function({ code }) { | ||
return new Promise((resolve, reject) => { | ||
if (code === "123456") resolve({ status: "approved" }); | ||
else resolve({ status: "rejected" }); | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
}; | ||
this.verify = verify; | ||
} | ||
} | ||
|
||
it("is false if the verification is wrong", () => { | ||
const client = new FakeClient(); | ||
client.verify("zep", "123400").then(result => { | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
|
||
it("return true from the promise ", () => { | ||
const client = new FakeClient(); | ||
client.verify("zep", "123456").then(result => { | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
}); |