Skip to content

Commit cbf1b24

Browse files
committed
feat(core): update-menu use-case
1 parent fe130b9 commit cbf1b24

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Menu from '../../entities/menu'
2+
3+
declare namespace UpdateMenuDTO {
4+
export interface Input {
5+
workspaceId: string
6+
data: Menu[]
7+
}
8+
9+
export interface Output {}
10+
}
11+
12+
export default UpdateMenuDTO
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { test } from '@japa/runner'
2+
import Menu from '../../entities/menu'
3+
4+
import InMemoryApp from '../../__tests__/app'
5+
import UpdateMenu from './update-menu'
6+
7+
test.group('update-menu (use-case)', (group) => {
8+
const app = new InMemoryApp()
9+
const useCase = new UpdateMenu(app)
10+
11+
group.each.teardown(() => app.memoryDrive.clear())
12+
13+
test('should update menu', async ({ expect }) => {
14+
const workspace = app.workspaceRepository.createFakeSync()
15+
16+
app.memoryDrive.createFile(
17+
'.is/menu.json',
18+
JSON.stringify([
19+
{
20+
label: 'item-initial',
21+
to: 'item-initial',
22+
},
23+
])
24+
)
25+
26+
const payload = {
27+
to: 'item-update',
28+
label: 'item-update',
29+
}
30+
31+
await useCase.execute({
32+
workspaceId: workspace.id,
33+
data: [payload],
34+
})
35+
36+
const menu = await app.memoryDrive.readArray('.is/menu.json')
37+
38+
expect(menu[0]).toEqual(payload)
39+
})
40+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import UpdateMenuDTO from './update-menu.dto'
2+
import AppService from '../../services/app-service'
3+
import WorkspaceService from '../../services/workspace-service'
4+
5+
export default class UpdateMenu {
6+
constructor(private readonly app: AppService) {}
7+
8+
public async execute({
9+
workspaceId,
10+
data,
11+
}: UpdateMenuDTO.Input): Promise<UpdateMenuDTO.Output> {
12+
const workspace = await WorkspaceService.from(this.app, workspaceId)
13+
14+
await workspace.drive.write('.is/menu.json', JSON.stringify(data, null, 4))
15+
16+
return {}
17+
}
18+
}

0 commit comments

Comments
 (0)