Skip to content

Commit

Permalink
refactor: change all toCalledWith to toHaveBeenCalledWith
Browse files Browse the repository at this point in the history
  • Loading branch information
Williancc1557 committed Mar 26, 2024
1 parent cfbd15e commit f96987b
Show file tree
Hide file tree
Showing 15 changed files with 1,623 additions and 1,968 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ test("should Teste.paragraph is called with valid param", () => {
sut.paragraph("willian");

// aqui eu verifico se a dependência foi chamada com o parâmetro correto
expect(makeParagraphSpy).toBeCalledWith("willian");
expect(makeParagraphSpy).toHaveBeenCalledWith("willian");
});
```

Expand Down
2 changes: 1 addition & 1 deletion jest-mongodb-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
dbName: "jest",
},
binary: {
version: "4.0.3",
version: "7.0.0",
skipMD5: true,
},
autoStart: false,
Expand Down
62 changes: 31 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,44 @@
"test:ci": "yarn test -- --coverage"
},
"devDependencies": {
"@shelf/jest-mongodb": "^4.0.0",
"@shelf/jest-mongodb": "^4.2.0",
"@techmmunity/eslint-config": "^5.2.3",
"@types/bcrypt": "^5.0.0",
"@types/express": "^4.17.13",
"@types/jest": "^28.1.6",
"@types/jsonwebtoken": "^8.5.8",
"@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/jsonwebtoken": "^9.0.6",
"@types/pino": "^7.0.5",
"@types/pino-http": "^5.8.1",
"@types/pino-pretty": "^4.7.5",
"@types/request-ip": "^0.0.39",
"@types/supertest": "^2.0.12",
"@types/pino-http": "^5.8.4",
"@types/pino-pretty": "^5.0.0",
"@types/request-ip": "^0.0.41",
"@types/supertest": "^6.0.2",
"@types/uuidv4": "^5.0.0",
"@types/validator": "^13.7.4",
"eslint": "^8.20.0",
"git-commit-msg-linter": "^4.1.3",
"husky": "^8.0.1",
"jest": "^28.1.3",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"supertest": "^6.2.4",
"ts-jest": "^28.0.7",
"@types/validator": "^13.11.9",
"eslint": "^8.57.0",
"git-commit-msg-linter": "^5.0.7",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"supertest": "^6.3.4",
"ts-jest": "^29.1.2",
"ts-node-dev": "^2.0.0",
"tsx": "^3.12.7",
"typescript": "5.1.6"
"tsx": "^4.7.1",
"typescript": "5.4.3"
},
"dependencies": {
"bcrypt": "^5.0.1",
"dotenv": "^16.0.3",
"express": "^4.18.1",
"express-rate-limit": "^7.1.0",
"jsonwebtoken": "^8.5.1",
"mongodb": "^4.8.0",
"pino": "^8.3.0",
"pino-http": "^8.1.1",
"pino-pretty": "^8.1.0",
"bcrypt": "^5.1.1",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"express-rate-limit": "^7.2.0",
"jsonwebtoken": "^9.0.2",
"mongodb": "^6.5.0",
"pino": "^8.19.0",
"pino-http": "^9.0.0",
"pino-pretty": "^11.0.0",
"request-ip": "^3.3.0",
"tsup": "^6.7.0",
"tsup": "^8.0.2",
"uid": "^2.0.0",
"validator": "^13.7.0"
"validator": "^13.11.0"
}
}
2 changes: 1 addition & 1 deletion src/data/usecase/add-account/add-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe("DbAddAccount", () => {
password: "valid_password",
});

expect(addAccountRepositorySpy).toBeCalledWith({
expect(addAccountRepositorySpy).toHaveBeenCalledWith({
name: "valid_name",
email: "[email protected]",
password: "hashed_value",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("GetAccountByEmail", () => {

await sut.get("[email protected]");

expect(getAccountByEmailRepositorySpy).toBeCalledWith(
expect(getAccountByEmailRepositorySpy).toHaveBeenCalledWith(
"[email protected]"
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("DbResetRefreshToken", () => {

await sut.reset(userId);

expect(resetRefreshTokenRepositorySpy).toBeCalledWith("validUserId");
expect(resetRefreshTokenRepositorySpy).toHaveBeenCalledWith("validUserId");
});

test("should return string if success", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ describe("TokenInfo Validation", () => {
validations.push(new RequiredFieldValidation(field));
}

expect(ValidationComposite).toBeCalledWith(validations);
expect(ValidationComposite).toHaveBeenCalledWith(validations);
});
});
2 changes: 1 addition & 1 deletion src/main/factories/sign-in/sign-in-validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ describe("TokenInfo Validation", () => {
new PasswordValidation("password", new UtilPasswordValidator())
);

expect(ValidationComposite).toBeCalledWith(validations);
expect(ValidationComposite).toHaveBeenCalledWith(validations);
});
});
2 changes: 1 addition & 1 deletion src/main/factories/sign-up/sign-up-validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ describe("TokenInfo Validation", () => {
new PasswordValidation("password", new UtilPasswordValidator())
);

expect(ValidationComposite).toBeCalledWith(validations);
expect(ValidationComposite).toHaveBeenCalledWith(validations);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ describe("TokenInfo Validation", () => {
validations.push(new RequiredFieldValidation(field));
}

expect(ValidationComposite).toBeCalledWith(validations);
expect(ValidationComposite).toHaveBeenCalledWith(validations);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ describe("RefreshToken Controller", () => {
const checkRefreshTokenSpy = checkRefreshTokenStub.check;
await sut.handle(makeFakeHttpRequest());

expect(checkRefreshTokenSpy).toBeCalledWith("valid_access_token");
expect(checkRefreshTokenSpy).toHaveBeenCalledWith("valid_access_token");
});

test("should create access is called with correct id", async () => {
const { sut, createAccessTokenStub } = makeSut();
const createAccessTokenSpy = createAccessTokenStub.create;
await sut.handle(makeFakeHttpRequest());

expect(createAccessTokenSpy).toBeCalledWith("valid_user_id");
expect(createAccessTokenSpy).toHaveBeenCalledWith("valid_user_id");
});

test("should return 200 if success", async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/presentation/controller/sign-in/sign-in.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ describe("SignIn Controller", () => {
const { sut, resetRefreshTokenStub } = makeSut();
await sut.handle(makeFakeHttpRequest());

expect(resetRefreshTokenStub.reset).toBeCalledWith("valid_id");
expect(resetRefreshTokenStub.reset).toHaveBeenCalledWith("valid_id");
});

test("should encrypter.compare is called with correct values", async () => {
const { sut, encrypterStub } = makeSut();
await sut.handle(makeFakeHttpRequest());

expect(encrypterStub.compare).toBeCalledWith(
expect(encrypterStub.compare).toHaveBeenCalledWith(
"valid_password",
"hashed_password"
);
Expand Down
4 changes: 2 additions & 2 deletions src/presentation/controller/sign-up/sign-up.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe("Sign-Up", () => {
const getAccountByEmailSpy = jest.spyOn(getAccountByEmailStub, "get");
await sut.handle(makeFakeHttpRequest());

expect(getAccountByEmailSpy).toBeCalledWith("[email protected]");
expect(getAccountByEmailSpy).toHaveBeenCalledWith("[email protected]");
});

test("should returns statusCode 409 if account already exists", async () => {
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("Sign-Up", () => {
const addAccountSpy = jest.spyOn(addAccountStub, "add");
await sut.handle(makeFakeHttpRequest());

expect(addAccountSpy).toBeCalledWith({
expect(addAccountSpy).toHaveBeenCalledWith({
name: "valid_name",
email: "[email protected]",
password: "valid_password",
Expand Down
4 changes: 2 additions & 2 deletions src/presentation/controller/token-info/token-info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("TokenInfo controller", () => {
const getTokenInfoSpy = jest.spyOn(getTokenInfoStub, "get");
await sut.handle(makeFakeHttpRequest());

expect(getTokenInfoSpy).toBeCalledWith("valid_access_token");
expect(getTokenInfoSpy).toHaveBeenCalledWith("valid_access_token");
});

test("should return statusCode 500 if GetTokenInfo dependency throws", async () => {
Expand Down Expand Up @@ -122,7 +122,7 @@ describe("TokenInfo controller", () => {
const validateSpy = jest.spyOn(validationStub, "validate");
await sut.handle(makeFakeHttpRequest());

expect(validateSpy).toBeCalledWith(makeFakeHttpRequest().header);
expect(validateSpy).toHaveBeenCalledWith(makeFakeHttpRequest().header);
});

test("should return 400 if Validation returns an error", async () => {
Expand Down
Loading

0 comments on commit f96987b

Please sign in to comment.