Skip to content

Commit

Permalink
test: removed field's login and password in the database
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielAraldi committed Jan 19, 2024
1 parent e3e2977 commit 7443ed6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
9 changes: 8 additions & 1 deletion tests/data/usecases/db-send-mail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ describe('DbSendMail Usecase', () => {
const mail = mockSendMailParams();
nodemailerSpy.create();
await sut.send(mail);
expect(sendPrismaRepository.data).toEqual(mail);
const { from, message, title, to, username } = mail;
expect(sendPrismaRepository.data).toEqual({
from,
message,
title,
to,
username,
});
});

test('Should throw error if send() from SendPrismaRepository throws', async () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/infra/db/prisma/send-prisma-repository.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PrismaClient } from '@prisma/client';
import { PrismaHelper, SendPrismaRepository } from '../../../../src/infra/db';
import { SendEmailRepository } from '../../../../src/data/protocols/db';
import { mockSendMailParams } from '../../../../tests/domain/mocks';
import { mockMailDatabaseParams } from '../../mocks';

let mailTable: PrismaClient['mail'];

Expand All @@ -24,8 +24,8 @@ describe('SendPrismaRepository', () => {
describe('send()', () => {
test('Should return true if the email was sent.', async () => {
const sut = makeSut();
const sendMailParams = mockSendMailParams();
const isValid = await sut.send(sendMailParams);
const mailDatabaseParams = mockMailDatabaseParams();
const isValid = await sut.send(mailDatabaseParams);
expect(isValid).toBe(true);
});
});
Expand Down
5 changes: 2 additions & 3 deletions tests/infra/mocks/in-memory-send-repository.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { SendEmailRepository } from '../../../src/data/protocols/db';
import { MailModel } from '../../../src/domain';

export class InMemorySendRepository implements SendEmailRepository {
private readonly table: MailModel[] = [];
public data: MailModel;
private readonly table: SendEmailRepository.Params[] = [];
public data: SendEmailRepository.Params;

async send(
data: SendEmailRepository.Params
Expand Down
1 change: 1 addition & 0 deletions tests/infra/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './in-memory-send-repository';
export * from './mock-mail-database';
10 changes: 10 additions & 0 deletions tests/infra/mocks/mock-mail-database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { SendEmailRepository } from '../../../src/data/protocols/db';
import { faker } from '@faker-js/faker';

export const mockMailDatabaseParams = (): SendEmailRepository.Params => ({
from: faker.internet.email(),
message: faker.lorem.words(),
title: faker.lorem.word(),
username: faker.person.fullName(),
to: [faker.internet.email(), faker.internet.email()],
});

0 comments on commit 7443ed6

Please sign in to comment.