Skip to content

Commit

Permalink
feat(pmp): pr changes
Browse files Browse the repository at this point in the history
refs #107
  • Loading branch information
ABartoszko committed May 20, 2020
1 parent e620702 commit b2dcf79
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNumber, IsOptional } from 'class-validator';

export class EditRepositoryDto {
@ApiProperty()
@IsNumber()
@IsOptional()
maxLines?: number;

@ApiProperty()
@IsNumber()
@IsOptional()
maxWaitingTime?: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { EditRepositoryHandler } from './edit-repository.handler';
import { EditRepositoryCommand } from './edit-repository.command';
import { RepositoryRepository } from '@pimp-my-pr/server/repository/core/domain-services';
import { Test } from '@nestjs/testing';
import { RepositoryEntity } from '@pimp-my-pr/server/repository/core/domain';
import Mocked = jest.Mocked;

describe('Edit Repository Handler', () => {
let editRepositoryHandler: EditRepositoryHandler;
let repositoryRepository: Mocked<RepositoryRepository>;
const repository = new RepositoryEntity('123', 'test', 'test', 'test', '1');

beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [
{
provide: RepositoryRepository,
useValue: {}
},
EditRepositoryHandler
]
}).compile();

repositoryRepository = module.get(RepositoryRepository);
editRepositoryHandler = module.get<EditRepositoryHandler>(EditRepositoryHandler);
});

describe('update', () => {
it('execute save repository', async () => {
const command: EditRepositoryCommand = {
repositoryId: '123',
maxLines: 2,
maxWaitingTime: 3
};

repositoryRepository.getById = jest.fn();
repositoryRepository.getById.mockResolvedValue(repository);

repository.edit = jest.fn();
repositoryRepository.save = jest.fn();

await editRepositoryHandler.execute(command);
expect(repository.edit).toHaveBeenCalledWith({
maxLines: command.maxLines,
maxWaitingTime: command.maxWaitingTime
});

expect(repositoryRepository.save).toHaveBeenCalledWith(repository);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { RepositoryRepository } from '@pimp-my-pr/server/repository/core/domain-services';
import { EditRepositoryCommand } from './edit-repository.command';
import { RepositoryEntity } from '@pimp-my-pr/server/repository/core/domain';

@CommandHandler(EditRepositoryCommand)
export class EditRepositoryHandler implements ICommandHandler<EditRepositoryCommand> {
Expand All @@ -10,10 +9,10 @@ export class EditRepositoryHandler implements ICommandHandler<EditRepositoryComm
async execute(command: EditRepositoryCommand): Promise<void> {
const { repositoryId, maxLines, maxWaitingTime } = command;

const repositoryData = await this.repositoryRepository.getById(repositoryId);
const repository = await this.repositoryRepository.getById(repositoryId);

const updatedRepository = { ...repositoryData, maxLines, maxWaitingTime } as RepositoryEntity;
repository.edit({ maxLines, maxWaitingTime });

return this.repositoryRepository.save(updatedRepository);
return this.repositoryRepository.save(repository);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { f } from '@marcj/marshal';
import { PrEntity } from './pr.entity';
import { RepositoryEditWriteModel } from '@pimp-my-pr/shared/domain';

export class RepositoryEntity {
@f.primary()
Expand Down Expand Up @@ -50,4 +51,9 @@ export class RepositoryEntity {
this.maxWaitingTime = maxWaitingTime;
this.maxLines = maxLines;
}

edit(writeModel: RepositoryEditWriteModel): void {
this.maxLines = writeModel.maxLines;
this.maxWaitingTime = writeModel.maxWaitingTime;
}
}
1 change: 1 addition & 0 deletions libs/shared/domain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './lib/interfaces/pr-author.interface';
export * from './lib/interfaces/pr-reviewer.interface';
export * from './lib/interfaces/pr.statistics';
export * from './lib/interfaces/repository.model';
export * from './lib/interfaces/repository-edit-write.model';
export * from './lib/interfaces/repository-statistics.interface';
export * from './lib/read-models/user.read-model';
export * from './lib/responses/api-repository-statistics.response';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface RepositoryEditWriteModel {
maxLines?: number;
maxWaitingTime?: number;
}

0 comments on commit b2dcf79

Please sign in to comment.