Skip to content

Commit

Permalink
updated ci
Browse files Browse the repository at this point in the history
  • Loading branch information
nokibul committed Mar 26, 2024
1 parent 754802c commit c44997a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 58 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/first-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ jobs:
postgres:
image: postgres
env:
POSTGRES_USER: my_database
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/db
options: >-
--health-cmd pg_isready
--health-interval 10s
Expand Down
109 changes: 54 additions & 55 deletions src/modules/account/account.repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,73 @@ import { AccountRepository } from './account.repository';
import { AccountDTO, Gender } from './account.dto';

function generateRandomEmail(): string {
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
let email = '';
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
let email = '';

for (let i = 0; i < 10; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
email += characters[randomIndex];
}
for (let i = 0; i < 10; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
email += characters[randomIndex];
}

email += '@example.com';
email += '@example.com';

return email;
return email;
}


describe('AccountRepository', () => {
let accountRepository: AccountRepository;
let accountRepository: AccountRepository;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AccountRepository],
}).compile();
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AccountRepository],
}).compile();

accountRepository = module.get<AccountRepository>(AccountRepository);
});
accountRepository = module.get<AccountRepository>(AccountRepository);
});

describe('create', () => {
it('should create a new account', async () => {
// Arrange
const signupDto: AccountDTO = {
name: generateRandomEmail(),
firstName: 'John',
lastName: 'Doe',
email: generateRandomEmail(),
birthDate: new Date('1990-01-01'),
password: 'securePassword123',
contactNo: generateRandomEmail(),
gender: Gender.male,
secondaryEmail: 'john.alt@example.com',
location: 'City, Country',
about: 'A brief description about John Doe',
};
describe('create', () => {
it('should create a new account', async () => {
// Arrange
const signupDto: AccountDTO = {
name: generateRandomEmail(),
firstName: 'John',
lastName: 'Doe',
email: generateRandomEmail(),
birthDate: new Date('1990-01-01'),
password: 'securePassword123',
contactNo: generateRandomEmail(),
gender: Gender.male,
secondaryEmail: 'john.alt@example.com',
location: 'City, Country',
about: 'A brief description about John Doe',
};

// Act
const createSpy = jest.spyOn(accountRepository, 'create');
const result = await accountRepository.create(signupDto);
// Act
const createSpy = jest.spyOn(accountRepository, 'create');
const result = await accountRepository.create(signupDto);

// Assert
expect(createSpy).toHaveBeenCalledWith(signupDto);
expect(result).toBeDefined();
expect(result.name).toEqual(signupDto.name);
expect(result.email).toEqual(signupDto.email);
expect(createSpy).toHaveBeenCalledTimes(1);
});
// Assert
expect(createSpy).toHaveBeenCalledWith(signupDto);
expect(result).toBeDefined();
expect(result.name).toEqual(signupDto.name);
expect(result.email).toEqual(signupDto.email);
expect(createSpy).toHaveBeenCalledTimes(1);
});
});

describe('findByEmail', () => {
it('should find an account by email', async () => {
// Arrange
const email = 'stringdf2@gmail.com';
describe('findByEmail', () => {
it('should find an account by email', async () => {
// Arrange
const email = 'stringdf2@gmail.com';

// Act
const findByEmailSpy = jest.spyOn(accountRepository, 'findByEmail');
const result = await accountRepository.findByEmail(email);
// Act
const findByEmailSpy = jest.spyOn(accountRepository, 'findByEmail');
const result = await accountRepository.findByEmail(email);

// Assert
expect(findByEmailSpy).toHaveBeenCalledWith(email);
expect(result).toBeDefined();
expect(result.email).toEqual(email);
});
// Assert
expect(findByEmailSpy).toHaveBeenCalledWith(email);
expect(result).toBeDefined();
expect(result.email).toEqual(email);
});
});
});
});

0 comments on commit c44997a

Please sign in to comment.