mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
feat: include responses from Exceptions
This commit is contained in:
1 parent
0f0f43b838
commit
254e4f75ed
3 files changed
+18
-13
No files matched your search
@@ -1,14 +1,7 @@
|
|||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
import { Condition } from './condition/Condition'
|
|
||||||
import { Event } from './Event'
|
import { Event } from './Event'
|
||||||
import { GlobalException, StageException } from './Exception'
|
import { GlobalException } from './Exception'
|
||||||
import {
|
import { IQuest, IFileExistenceChecker, ICommand, IResponse } from './schema'
|
||||||
IQuest,
|
|
||||||
IStage,
|
|
||||||
IFileExistenceChecker,
|
|
||||||
ICommand,
|
|
||||||
IResponse,
|
|
||||||
} from './schema'
|
|
||||||
import { Stage } from './Stage'
|
import { Stage } from './Stage'
|
||||||
|
|
||||||
export class Quest {
|
export class Quest {
|
||||||
@@ -72,8 +65,6 @@ export class Quest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getResponses(completed: string[]): IResponse[] {
|
getResponses(completed: string[]): IResponse[] {
|
||||||
return this.quest.stages
|
return completed.map((id) => this.events.get(id)!.getResponse())
|
||||||
.filter((stage) => completed.includes(stage.id))
|
|
||||||
.map((stage) => stage.response)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,6 @@ describe('exceptions', () => {
|
|||||||
)
|
)
|
||||||
expect(await session.runCommand({ command: 'ls' })).toBe('exception1')
|
expect(await session.runCommand({ command: 'ls' })).toBe('exception1')
|
||||||
await session.runCommand({ command: 'echo start' })
|
await session.runCommand({ command: 'echo start' })
|
||||||
console.log('completed', session.completedEvents)
|
|
||||||
expect(await session.runCommand({ command: 'ls' })).toBe('stage2')
|
expect(await session.runCommand({ command: 'ls' })).toBe('stage2')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,19 @@ const quest: IQuest = {
|
|||||||
response: { type: 'narrative', content: 'Narrative 4' },
|
response: { type: 'narrative', content: 'Narrative 4' },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
exceptions: [
|
||||||
|
{
|
||||||
|
id: 'exception1',
|
||||||
|
condition: {
|
||||||
|
command: 'rm',
|
||||||
|
},
|
||||||
|
response: {
|
||||||
|
type: 'narrative',
|
||||||
|
content: 'Exception 1',
|
||||||
|
},
|
||||||
|
requirements: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Session', () => {
|
describe('Session', () => {
|
||||||
@@ -108,9 +121,11 @@ describe('Session', () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
session.complete('exception1')
|
||||||
session.complete('stage2')
|
session.complete('stage2')
|
||||||
expect(session.getResponses()).toEqual([
|
expect(session.getResponses()).toEqual([
|
||||||
{ type: 'narrative', content: 'Narrative 1' },
|
{ type: 'narrative', content: 'Narrative 1' },
|
||||||
|
{ type: 'narrative', content: 'Exception 1' },
|
||||||
{ type: 'narrative', content: 'Narrative 2' },
|
{ type: 'narrative', content: 'Narrative 2' },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user