-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pmp): edit repository in settings - backend
refs #107
- Loading branch information
1 parent
02cdbdc
commit 26f5187
Showing
11 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
libs/server/repository/api-rest/src/lib/dtos/edit-repository.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...ory/core/application-services/src/lib/commands/edit-repository/edit-repository.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class EditRepositoryCommand { | ||
constructor( | ||
public repositoryId: string, | ||
public maxLines?: number, | ||
public maxWaitingTime?: number | ||
) {} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ore/application-services/src/lib/commands/edit-repository/edit-repository.handler.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
...ory/core/application-services/src/lib/commands/edit-repository/edit-repository.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { RepositoryRepository } from '@pimp-my-pr/server/repository/core/domain-services'; | ||
import { EditRepositoryCommand } from './edit-repository.command'; | ||
|
||
@CommandHandler(EditRepositoryCommand) | ||
export class EditRepositoryHandler implements ICommandHandler<EditRepositoryCommand> { | ||
constructor(private repositoryRepository: RepositoryRepository) {} | ||
|
||
async execute(command: EditRepositoryCommand): Promise<void> { | ||
const { repositoryId, maxLines, maxWaitingTime } = command; | ||
|
||
const repository = await this.repositoryRepository.getById(repositoryId); | ||
|
||
repository.edit({ maxLines, maxWaitingTime }); | ||
|
||
return this.repositoryRepository.save(repository); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
libs/shared/domain/src/lib/interfaces/repository-edit-write.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface RepositoryEditWriteModel { | ||
maxLines?: number; | ||
maxWaitingTime?: number; | ||
} |