Skip to content

Commit

Permalink
fix: build is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Williancc1557 committed Oct 5, 2023
1 parent e4296b7 commit 508c45b
Show file tree
Hide file tree
Showing 126 changed files with 2,685 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .env.docker
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
2 changes: 2 additions & 0 deletions build/data/protocols/add-account-repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 2 additions & 0 deletions build/data/protocols/create-access-token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 2 additions & 0 deletions build/data/protocols/create-refresh-token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 2 additions & 0 deletions build/data/protocols/encrypter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 2 additions & 0 deletions build/data/protocols/get-account-by-email-repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 2 additions & 0 deletions build/data/protocols/get-account-by-id-repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 2 additions & 0 deletions build/data/protocols/get-refresh-token-repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
23 changes: 23 additions & 0 deletions build/data/protocols/index.js
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);
2 changes: 2 additions & 0 deletions build/data/protocols/reset-refresh-token-repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
18 changes: 18 additions & 0 deletions build/data/usecase/add-account/add-account.js
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;
85 changes: 85 additions & 0 deletions build/data/usecase/add-account/add-account.spec.js
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 build/data/usecase/check-refresh-token/check-refresh-token.js
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 build/data/usecase/check-refresh-token/check-refresh-token.spec.js
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 build/data/usecase/get-account-by-email/get-account-by-email.js
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;
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",
});
});
});
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;
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 build/data/usecase/reset-refresh-token/reset-refresh-token.js
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 build/data/usecase/reset-refresh-token/reset-refresh-token.spec.js
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");
});
});
Loading

0 comments on commit 508c45b

Please sign in to comment.