-
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
1 parent
e4296b7
commit 508c45b
Showing
126 changed files
with
2,685 additions
and
10 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,2 +1,2 @@ | ||
PORT=8080 | ||
MONGO_URL=mongodb:https://mongodb:27017/todo-list | ||
MONGO_URL=mongodb:https://mongodb:27018/todo-list |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,23 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./add-account-repository"), exports); | ||
__exportStar(require("./create-access-token"), exports); | ||
__exportStar(require("./create-refresh-token"), exports); | ||
__exportStar(require("./encrypter"), exports); | ||
__exportStar(require("./get-account-by-email-repository"), exports); | ||
__exportStar(require("./get-refresh-token-repository"), exports); | ||
__exportStar(require("./reset-refresh-token-repository"), exports); |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DbAddAccount = void 0; | ||
class DbAddAccount { | ||
constructor(addAccountRepository, encrypter) { | ||
this.addAccountRepository = addAccountRepository; | ||
this.encrypter = encrypter; | ||
} | ||
async add(account) { | ||
const hashedPassword = await this.encrypter.hash(account.password); | ||
const accountData = await this.addAccountRepository.add({ | ||
...account, | ||
password: hashedPassword, | ||
}); | ||
return accountData; | ||
} | ||
} | ||
exports.DbAddAccount = DbAddAccount; |
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,85 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const add_account_1 = require("./add-account"); | ||
const makeAddAccountRepositoryStub = () => { | ||
class AddAccountRepositoryStub { | ||
async add( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
account) { | ||
return { | ||
id: "valid_id", | ||
name: "valid_name", | ||
email: "[email protected]", | ||
password: "hashed_password", | ||
refreshToken: "valid_refreshToken", | ||
accessToken: "valid_accessToken", | ||
expiresIn: 300, | ||
}; | ||
} | ||
} | ||
return new AddAccountRepositoryStub(); | ||
}; | ||
const makeEncrypterStub = () => { | ||
class EncrypterStub { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
async hash(value) { | ||
return "hashed_value"; | ||
} | ||
} | ||
return new EncrypterStub(); | ||
}; | ||
const makeSut = () => { | ||
const addAccountRepositoryStub = makeAddAccountRepositoryStub(); | ||
const encrypterStub = makeEncrypterStub(); | ||
const sut = new add_account_1.DbAddAccount(addAccountRepositoryStub, encrypterStub); | ||
return { | ||
sut, | ||
addAccountRepositoryStub, | ||
encrypterStub, | ||
}; | ||
}; | ||
describe("DbAddAccount", () => { | ||
test("should throw if addAccountRepository throws", async () => { | ||
const { sut, addAccountRepositoryStub } = makeSut(); | ||
jest | ||
.spyOn(addAccountRepositoryStub, "add") | ||
.mockRejectedValueOnce(new Error()); | ||
const req = sut.add({ | ||
name: "valid_name", | ||
email: "[email protected]", | ||
password: "valid_password", | ||
}); | ||
await expect(req).rejects.toThrow(); | ||
}); | ||
test("should check if addAccountRepository is called with valid value", async () => { | ||
const { sut, addAccountRepositoryStub } = makeSut(); | ||
const addAccountRepositorySpy = jest.spyOn(addAccountRepositoryStub, "add"); | ||
await sut.add({ | ||
name: "valid_name", | ||
email: "[email protected]", | ||
password: "valid_password", | ||
}); | ||
expect(addAccountRepositorySpy).toBeCalledWith({ | ||
name: "valid_name", | ||
email: "[email protected]", | ||
password: "hashed_value", | ||
}); | ||
}); | ||
test("should return account if success", async () => { | ||
const { sut } = makeSut(); | ||
const req = await sut.add({ | ||
name: "valid_name", | ||
email: "[email protected]", | ||
password: "valid_password", | ||
}); | ||
expect(req).toStrictEqual({ | ||
id: "valid_id", | ||
name: "valid_name", | ||
email: "[email protected]", | ||
password: "hashed_password", | ||
refreshToken: "valid_refreshToken", | ||
accessToken: "valid_accessToken", | ||
expiresIn: 300, | ||
}); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
build/data/usecase/check-refresh-token/check-refresh-token.js
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,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DbCheckRefreshToken = void 0; | ||
class DbCheckRefreshToken { | ||
constructor(getRefreshTokenRepository) { | ||
this.getRefreshTokenRepository = getRefreshTokenRepository; | ||
} | ||
async check(refreshToken) { | ||
const account = await this.getRefreshTokenRepository.get(refreshToken); | ||
return account === null || account === void 0 ? void 0 : account.id; | ||
} | ||
} | ||
exports.DbCheckRefreshToken = DbCheckRefreshToken; |
45 changes: 45 additions & 0 deletions
45
build/data/usecase/check-refresh-token/check-refresh-token.spec.js
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,45 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const check_refresh_token_1 = require("./check-refresh-token"); | ||
const makeGetRefreshTokenStub = () => { | ||
class GetRefreshTokenStub { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
async get(refreshToken) { | ||
return { | ||
id: "valid_id", | ||
email: "[email protected]", | ||
name: "valid_name", | ||
password: "valid_password", | ||
refreshToken: "valid_refresh_token", | ||
}; | ||
} | ||
} | ||
return new GetRefreshTokenStub(); | ||
}; | ||
const makeSut = () => { | ||
const getRefreshTokenStub = makeGetRefreshTokenStub(); | ||
const sut = new check_refresh_token_1.DbCheckRefreshToken(getRefreshTokenStub); | ||
return { | ||
sut, | ||
getRefreshTokenStub, | ||
}; | ||
}; | ||
describe("CheckRefreshToken", () => { | ||
test("should return undefined if account don't exists", async () => { | ||
const { sut, getRefreshTokenStub } = makeSut(); | ||
jest.spyOn(getRefreshTokenStub, "get").mockResolvedValueOnce(undefined); | ||
const res = await sut.check("valid_refresh_token"); | ||
expect(res).toBeUndefined(); | ||
}); | ||
test("should call getRefreshToken with correct values", async () => { | ||
const { sut, getRefreshTokenStub } = makeSut(); | ||
const getRefreshTokenSpy = jest.spyOn(getRefreshTokenStub, "get"); | ||
await sut.check("valid_refresh_token"); | ||
expect(getRefreshTokenSpy).toBeCalledWith("valid_refresh_token"); | ||
}); | ||
test("should return account.id if success", async () => { | ||
const { sut } = makeSut(); | ||
const res = await sut.check("valid_refresh_token"); | ||
expect(res).toBe("valid_id"); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
build/data/usecase/get-account-by-email/get-account-by-email.js
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,12 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DbGetAccountByEmail = void 0; | ||
class DbGetAccountByEmail { | ||
constructor(getAccountByEmailRepository) { | ||
this.getAccountByEmailRepository = getAccountByEmailRepository; | ||
} | ||
async get(email) { | ||
return this.getAccountByEmailRepository.get(email); | ||
} | ||
} | ||
exports.DbGetAccountByEmail = DbGetAccountByEmail; |
53 changes: 53 additions & 0 deletions
53
build/data/usecase/get-account-by-email/get-account-by-email.spec.js
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,53 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const get_account_by_email_1 = require("./get-account-by-email"); | ||
const makeGetAccountByEmailRepositoryStub = () => { | ||
class GetAccountByEmailRepositoryStub { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
async get(email) { | ||
return { | ||
id: "valid_id", | ||
email: "[email protected]", | ||
name: "valid_name", | ||
password: "valid_password", | ||
refreshToken: "valid_refresh_token", | ||
}; | ||
} | ||
} | ||
return new GetAccountByEmailRepositoryStub(); | ||
}; | ||
const makeSut = () => { | ||
const getAccountByEmailRepositoryStub = makeGetAccountByEmailRepositoryStub(); | ||
const sut = new get_account_by_email_1.DbGetAccountByEmail(getAccountByEmailRepositoryStub); | ||
return { | ||
sut, | ||
getAccountByEmailRepositoryStub, | ||
}; | ||
}; | ||
describe("GetAccountByEmail", () => { | ||
test("should getAccountByEmailRepository is called with correct values", async () => { | ||
const { sut, getAccountByEmailRepositoryStub } = makeSut(); | ||
const getAccountByEmailRepositorySpy = jest.spyOn(getAccountByEmailRepositoryStub, "get"); | ||
await sut.get("[email protected]"); | ||
expect(getAccountByEmailRepositorySpy).toBeCalledWith("[email protected]"); | ||
}); | ||
test("should return null if email is not found", async () => { | ||
const { sut, getAccountByEmailRepositoryStub } = makeSut(); | ||
jest | ||
.spyOn(getAccountByEmailRepositoryStub, "get") | ||
.mockResolvedValueOnce(null); | ||
const req = await sut.get("[email protected]"); | ||
expect(req).not.toBeTruthy(); | ||
}); | ||
test("should return account if success", async () => { | ||
const { sut } = makeSut(); | ||
const req = await sut.get("[email protected]"); | ||
expect(req).toStrictEqual({ | ||
id: "valid_id", | ||
email: "[email protected]", | ||
name: "valid_name", | ||
password: "valid_password", | ||
refreshToken: "valid_refresh_token", | ||
}); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
build/data/usecase/is-valid-refresh-token/is-valid-refresh-token.js
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,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DbIsValidRefreshToken = void 0; | ||
class DbIsValidRefreshToken { | ||
constructor(getAccountById) { | ||
this.getAccountById = getAccountById; | ||
} | ||
async check(refreshToken, accountId) { | ||
const account = await this.getAccountById.get(accountId); | ||
return (account === null || account === void 0 ? void 0 : account.refreshToken) == refreshToken ? true : false; | ||
} | ||
} | ||
exports.DbIsValidRefreshToken = DbIsValidRefreshToken; |
44 changes: 44 additions & 0 deletions
44
build/data/usecase/is-valid-refresh-token/is-valid-refresh-token.spec.js
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,44 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const is_valid_refresh_token_1 = require("./is-valid-refresh-token"); | ||
const makeGetAccountByIdStub = () => { | ||
class GetAccountByIdStub { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
async get(accountId) { | ||
return { | ||
id: "valid_id", | ||
name: "valid_name", | ||
email: "[email protected]", | ||
password: "valid_password", | ||
refreshToken: "refresh_token", | ||
}; | ||
} | ||
} | ||
return new GetAccountByIdStub(); | ||
}; | ||
const makeSut = () => { | ||
const getAccountByIdStub = makeGetAccountByIdStub(); | ||
const sut = new is_valid_refresh_token_1.DbIsValidRefreshToken(getAccountByIdStub); | ||
return { | ||
sut, | ||
getAccountByIdStub, | ||
}; | ||
}; | ||
describe("DbIsValidRefreshToken", () => { | ||
test("should return false if getAccountByRefreshToken returns undefined", async () => { | ||
const { sut, getAccountByIdStub } = makeSut(); | ||
jest.spyOn(getAccountByIdStub, "get").mockResolvedValueOnce(undefined); | ||
const res = await sut.check("refresh_token", "valid_id"); | ||
expect(res).toBe(false); | ||
}); | ||
test("should throws if getAccountByRefreshToken throw", async () => { | ||
const { sut, getAccountByIdStub } = makeSut(); | ||
jest.spyOn(getAccountByIdStub, "get").mockRejectedValueOnce(new Error()); | ||
await expect(sut.check("refresh_token", "valid_id")).rejects.toThrow(); | ||
}); | ||
test("should return true if success", async () => { | ||
const { sut } = makeSut(); | ||
const res = await sut.check("refresh_token", "valid_id"); | ||
expect(res).toBe(true); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
build/data/usecase/reset-refresh-token/reset-refresh-token.js
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,12 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DbResetRefreshToken = void 0; | ||
class DbResetRefreshToken { | ||
constructor(resetRefreshTokenRepository) { | ||
this.resetRefreshTokenRepository = resetRefreshTokenRepository; | ||
} | ||
async reset(userId) { | ||
return this.resetRefreshTokenRepository.reset(userId); | ||
} | ||
} | ||
exports.DbResetRefreshToken = DbResetRefreshToken; |
35 changes: 35 additions & 0 deletions
35
build/data/usecase/reset-refresh-token/reset-refresh-token.spec.js
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,35 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const reset_refresh_token_1 = require("./reset-refresh-token"); | ||
const makeResetRefreshTokenRepositoryStub = () => { | ||
class ResetRefreshTokenRepositoryStub { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
async reset(userId) { | ||
return "refresh_token"; | ||
} | ||
} | ||
return new ResetRefreshTokenRepositoryStub(); | ||
}; | ||
const makeSut = () => { | ||
const resetRefreshTokenRepositoryStub = makeResetRefreshTokenRepositoryStub(); | ||
const sut = new reset_refresh_token_1.DbResetRefreshToken(resetRefreshTokenRepositoryStub); | ||
return { | ||
sut, | ||
resetRefreshTokenRepositoryStub, | ||
}; | ||
}; | ||
describe("DbResetRefreshToken", () => { | ||
test("should call resetRefreshToken with correct value", async () => { | ||
const { sut, resetRefreshTokenRepositoryStub } = makeSut(); | ||
const resetRefreshTokenRepositorySpy = jest.spyOn(resetRefreshTokenRepositoryStub, "reset"); | ||
const userId = "validUserId"; | ||
await sut.reset(userId); | ||
expect(resetRefreshTokenRepositorySpy).toBeCalledWith("validUserId"); | ||
}); | ||
test("should return string if success", async () => { | ||
const { sut } = makeSut(); | ||
const userId = "validUserId"; | ||
const res = await sut.reset(userId); | ||
expect(res).toBe("refresh_token"); | ||
}); | ||
}); |
Oops, something went wrong.