Skip to content

Commit

Permalink
Rename action to signUp user
Browse files Browse the repository at this point in the history
  • Loading branch information
mapeveri committed Dec 28, 2024
1 parent 363556b commit 9ce0093
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/account/_dependencyInjection/commandHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import UpdateUserCommandHandler from '@src/account/application/user/command/updateUserCommandHandler';
import SignupUserCommandHandler from '@src/account/application/auth/command/signupUserCommandHandler';
import SignUpUserCommandHandler from '@src/account/application/auth/command/signUpUserCommandHandler';

export const commands = [SignupUserCommandHandler, UpdateUserCommandHandler];
export const commands = [SignUpUserCommandHandler, UpdateUserCommandHandler];
4 changes: 2 additions & 2 deletions src/account/app/controllers/v1/auth/signupPostController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Body, Controller, HttpCode, Inject, Post } from '@nestjs/common';
import { ApiBadRequestResponse, ApiInternalServerErrorResponse, ApiTags } from '@nestjs/swagger';
import SignupPostDto from '@src/account/app/controllers/v1/auth/signupPostDto';
import { COMMAND_BUS, CommandBus } from '@src/shared/domain/bus/commandBus/commandBus';
import SignupUserCommand from '@src/account/application/auth/command/signupUserCommand';
import SignUpUserCommand from '@src/account/application/auth/command/signUpUserCommand';
import { Uuid } from '@src/shared/domain/valueObjects/uuid';

@ApiTags('Auth')
Expand All @@ -18,7 +18,7 @@ export default class SignupPostController {
const id = Uuid.fromString(payload.email).toString();

await this.commandBus.dispatch(
new SignupUserCommand(id, payload.name, payload.email, payload.token, payload.provider, payload.photo),
new SignUpUserCommand(id, payload.name, payload.email, payload.token, payload.provider, payload.photo),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from '@src/shared/domain/bus/commandBus/command';

export default class SignupUserCommand implements Command {
export default class SignUpUserCommand implements Command {
constructor(
public readonly id: string,
public readonly name: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { CommandHandler, ICommandHandler } from '@src/shared/domain/bus/commandBus/commandHandler';
import SignupUserCommand from '@src/account/application/auth/command/signupUserCommand';
import SignUpUserCommand from '@src/account/application/auth/command/signUpUserCommand';
import { Inject } from '@src/shared/domain/injector/inject.decorator';
import UserRepository, { USER_REPOSITORY } from '@src/account/domain/user/userRepository';
import { EVENT_BUS, EventBus } from '@src/shared/domain/bus/eventBus/eventBus';
import UserId from '@src/account/domain/user/userId';
import UserAlreadyExistsException from '@src/account/domain/user/userAlreadyExistsException';
import User from '@src/account/domain/user/user';

@CommandHandler(SignupUserCommand)
export default class SignupUserCommandHandler implements ICommandHandler<SignupUserCommand> {
@CommandHandler(SignUpUserCommand)
export default class SignUpUserCommandHandler implements ICommandHandler<SignUpUserCommand> {
constructor(
@Inject(USER_REPOSITORY) private readonly userRepository: UserRepository,
@Inject(EVENT_BUS) private readonly eventBus: EventBus,
) {}

async execute(command: SignupUserCommand): Promise<void> {
async execute(command: SignUpUserCommand): Promise<void> {
await this.guardUserDoesNotExists(command.id);

const user = User.create(command.id, command.name, command.provider, command.email, command.photo);
const user = User.signUp(command.id, command.name, command.provider, command.email, command.photo);

this.userRepository.save(user);

Expand Down
6 changes: 3 additions & 3 deletions src/account/domain/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AggregateRoot } from '@src/shared/domain/aggregate/aggregateRoot';
import UserId from './userId';
import Email from '@src/shared/domain/valueObjects/email';
import UserUpdatedEvent from '@src/account/domain/user/userUpdatedEvent';
import UserCreatedEvent from '@src/account/domain/user/userCreatedEvent';
import UserSignedUpEvent from '@src/account/domain/user/userSignedUpEvent';

export type UserPrimitives = {
id: string;
Expand All @@ -29,10 +29,10 @@ export default class User extends AggregateRoot {
return this.name;
}

static create(id: string, name: string, provider: string, email: string, photo: string): User {
static signUp(id: string, name: string, provider: string, email: string, photo: string): User {
const user = new this(UserId.of(id), name, provider, Email.of(email), photo, []);

user.record(new UserCreatedEvent(id.toString(), name, provider, email.toString(), photo));
user.record(new UserSignedUpEvent(id.toString(), name, provider, email.toString(), photo));

return user;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DomainEvent } from '@src/shared/domain/bus/eventBus/domainEvent';

export default class UserCreatedEvent extends DomainEvent {
export default class UserSignedUpEvent extends DomainEvent {
constructor(
public readonly id: string,
public readonly name: string,
Expand All @@ -24,11 +24,11 @@ export default class UserCreatedEvent extends DomainEvent {
}

public static eventTypeName(): string {
return 'user.created';
return 'user.signedUp';
}

public classPathName(): string {
return 'languages.domain.user.userCreatedEvent';
return 'languages.domain.user.userSignedUpEvent';
}

public static aggregateTypeName(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import request = require('supertest');
import { MikroORM } from '@mikro-orm/core';
import { createApplication, truncateTables } from '@test/acceptance/createApplication';

describe('Signup feature', () => {
describe('SignUp feature', () => {
let app: INestApplication;
let orm: MikroORM;

Expand All @@ -27,7 +27,7 @@ describe('Signup feature', () => {
await closeApp();
});

describe('As a user I want to signup in the app', () => {
describe('As a user I want to signUp in the app', () => {
async function startScenario() {
await truncateTables(orm);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeAll, describe, it, expect, jest } from '@jest/globals';
import SignupPostController from '@src/account/app/controllers/v1/auth/signupPostController';
import { CommandBus } from '@src/shared/domain/bus/commandBus/commandBus';
import { SignupUserCommandMother } from '@test/unit/account/application/auth/command/signupUserCommandMother';
import { SignUpUserCommandMother } from '@test/unit/account/application/auth/command/signUpUserCommandMother';

describe('Given a SignupPostController to handle', () => {
let sut: SignupPostController;
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('Given a SignupPostController to handle', () => {
await sut.run(data);

expect(commandBusMock.dispatch).toHaveBeenCalledWith(
SignupUserCommandMother.random({
SignUpUserCommandMother.random({
id: '4a4df157-8ab8-50af-bb39-88e8ce29eb16',
email: data.email,
name: data.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { beforeEach, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { EventBusMock } from '@test/unit/shared/domain/buses/eventBus/eventBusMock';
import SignupUserCommandHandler from '@src/account/application/auth/command/signupUserCommandHandler';
import { SignupUserCommandMother } from '@test/unit/account/application/auth/command/signupUserCommandMother';
import SignupUserCommand from '@src/account/application/auth/command/signupUserCommand';
import SignUpUserCommandHandler from '@src/account/application/auth/command/signUpUserCommandHandler';
import { SignUpUserCommandMother } from '@test/unit/account/application/auth/command/signUpUserCommandMother';
import SignUpUserCommand from '@src/account/application/auth/command/signUpUserCommand';
import { UserRepositoryMock } from '@test/unit/account/domain/user/userRepositoryMock';
import { UserMother } from '@test/unit/account/domain/user/userMother';
import UserAlreadyExistsException from '@src/account/domain/user/userAlreadyExistsException';
import { UserIdMother } from '@test/unit/account/domain/user/userIdMother';
import UserCreatedEvent from '@src/account/domain/user/userCreatedEvent';
import { UserCreatedEventMother } from '@test/unit/account/domain/user/userCreatedEventMother';
import UserSignedUpEvent from '@src/account/domain/user/userSignedUpEvent';
import { UserSignedUpEventMother } from '@test/unit/account/domain/user/userSignedUpEventMother';

describe('Given a SignupUserCommandHandler to handle', () => {
describe('Given a SignUpUserCommandHandler to handle', () => {
let userRepository: UserRepositoryMock;
let eventBus: EventBusMock;
let handler: SignupUserCommandHandler;
let handler: SignUpUserCommandHandler;

const prepareDependencies = () => {
userRepository = new UserRepositoryMock();
eventBus = new EventBusMock();
};

const initHandler = () => {
handler = new SignupUserCommandHandler(userRepository, eventBus);
handler = new SignUpUserCommandHandler(userRepository, eventBus);

jest.useFakeTimers();
};
Expand All @@ -41,10 +41,10 @@ describe('Given a SignupUserCommandHandler to handle', () => {
});

describe('When the user already exists', () => {
let command: SignupUserCommand;
let command: SignUpUserCommand;

function startScenario() {
command = SignupUserCommandMother.random();
command = SignUpUserCommandMother.random();
userRepository.add(UserMother.random({ id: UserIdMother.random(command.id) }));
}

Expand All @@ -66,7 +66,7 @@ describe('Given a SignupUserCommandHandler to handle', () => {

describe('When the user does not exists', () => {
let data: { id: string; email: string; provider: string; photo: string; name: string };
let command: SignupUserCommand;
let command: SignUpUserCommand;

function startScenario() {
data = {
Expand All @@ -76,7 +76,7 @@ describe('Given a SignupUserCommandHandler to handle', () => {
photo: '',
name: 'test',
};
command = SignupUserCommandMother.random(data);
command = SignUpUserCommandMother.random(data);
}

beforeEach(startScenario);
Expand All @@ -91,11 +91,11 @@ describe('Given a SignupUserCommandHandler to handle', () => {
});

it('should publish the events', async () => {
const event = UserCreatedEventMother.createFromSignupUserCommand(command);
const event = UserSignedUpEventMother.createFromSignUpUserCommand(command);
await handler.execute(command);

expect(eventBus.domainEvents()).toHaveLength(1);
expect(eventBus.domainEvents()[0]).toBeInstanceOf(UserCreatedEvent);
expect(eventBus.domainEvents()[0]).toBeInstanceOf(UserSignedUpEvent);
expect(eventBus.domainEvents()[0]).toEqual({
...event,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import faker from 'faker';
import SignupUserCommand from '@src/account/application/auth/command/signupUserCommand';
import SignUpUserCommand from '@src/account/application/auth/command/signUpUserCommand';

interface SignupUserCommandProps {
id?: string;
Expand All @@ -10,11 +10,11 @@ interface SignupUserCommandProps {
photo?: string;
}

export class SignupUserCommandMother {
static random(props?: SignupUserCommandProps): SignupUserCommand {
export class SignUpUserCommandMother {
static random(props?: SignupUserCommandProps): SignUpUserCommand {
const { id, name, email, token, provider, photo } = props ?? {};

return new SignupUserCommand(
return new SignUpUserCommand(
id ?? faker.datatype.uuid(),
name ?? faker.name.findName(),
email ?? faker.internet.email(),
Expand Down
10 changes: 0 additions & 10 deletions test/unit/account/domain/user/userCreatedEventMother.ts

This file was deleted.

10 changes: 10 additions & 0 deletions test/unit/account/domain/user/userSignedUpEventMother.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { expect } from '@jest/globals';
import SignUpUserCommand from '@src/account/application/auth/command/signUpUserCommand';
import UserSignedUpEvent from '@src/account/domain/user/userSignedUpEvent';

export class UserSignedUpEventMother {
static createFromSignUpUserCommand(command: SignUpUserCommand): UserSignedUpEvent {
const eventId = expect.any(String) as unknown as string;
return new UserSignedUpEvent(command.id, command.name, command.provider, command.email, command.photo, eventId);
}
}

0 comments on commit 9ce0093

Please sign in to comment.