-
Notifications
You must be signed in to change notification settings - Fork 13
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
1 parent
4cf441f
commit 22c1da4
Showing
2 changed files
with
49 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import sinon from "sinon"; | ||
import { DataSource, Repository } from "typeorm"; | ||
import { StatusCodes, getReasonPhrase } from "http-status-codes"; | ||
import { lambdaHandler } from "../handler"; | ||
import { expect } from "chai"; | ||
|
||
describe("GET /me", () => { | ||
let sandbox: sinon.SinonSandbox; | ||
let userRepositoryStub: sinon.SinonStub; | ||
const email = "[email protected]"; | ||
|
||
const profileModel = { | ||
id: "50ece88a-61ac-4435-8457-051693716276", | ||
firstName: "John", | ||
lastName: "Doe", | ||
email, | ||
}; | ||
|
||
const params = { email }; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
userRepositoryStub = sandbox.stub(Repository.prototype, "findOne"); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe("GET dev/users", () => { | ||
it("should return logged profile data", async () => { | ||
userRepositoryStub.resolves(profileModel); | ||
const response = await lambdaHandler({ queryStringParameters: params }); | ||
|
||
const parsedResponse = JSON.parse(response.body); | ||
expect(response.statusCode).to.equal(StatusCodes.OK); | ||
expect(parsedResponse.data).to.deep.equal(profileModel); | ||
}); | ||
|
||
it("should return error when profile wasn't found in database", async () => { | ||
try { | ||
await lambdaHandler({ queryStringParameters: params }); | ||
} catch(error: any) { | ||
expect(JSON.parse(error.message).message).to.be.equal(`User with email "${email}" does not exist`); | ||
} | ||
}); | ||
}); | ||
}); |