Skip to content

Commit

Permalink
Fix mock file not saved
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth committed Jul 17, 2019
1 parent d04201b commit f31f182
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/TodoActionsMain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ it('works', async () => {
'Somebody once told me',
])

// Idempotent check
await runMain()
expect(world.commits.length).toEqual(2)
expect(world.tasks.length).toEqual(2)

// Round 2: Arrange
const task1 = world.tasks.find(t => t.title === 'Hello world')!
const task2 = world.tasks.find(t => t.title === 'Somebody once told me')!
Expand Down
13 changes: 5 additions & 8 deletions src/__mocks__/CodeRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ export const repoContext: Real['repoContext'] = {
}

export const scanCodeRepository: Real['scanCodeRepository'] = async () => {
const files = [...mockWorld.files.values()]
return {
files: [...mockWorld.files.values()],
files: files,
isOnDefaultBranch: mockWorld.branch === repoContext.defaultBranch,
async saveChanges(commitMessage) {
if (![...mockWorld.files.values()].some(f => f.contents.changed)) return
if (!files.some(f => f.contents.changed)) return
files.forEach(f => f.save())
mockWorld.commits.push({
message: commitMessage,
files: new Map(
[...mockWorld.files.values()].map(f => [
f.fileName,
f.contents.toString(),
]),
),
files: new Map(files.map(f => [f.fileName, f.contents.toString()])),
})
},
}
Expand Down

0 comments on commit f31f182

Please sign in to comment.