mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
refactor: add new name "Event" for the set Stage and Exception
This commit is contained in:
1 parent
6e804f0ed4
commit
2dc40a2254
5 files changed
+13
-13
No files matched your search
@@ -37,7 +37,7 @@ export class Quest {
|
||||
)
|
||||
}
|
||||
|
||||
async findSatisfiedStage(
|
||||
async findSatisfiedEvent(
|
||||
command: ICommand,
|
||||
completed: string[]
|
||||
): Promise<string | null> {
|
||||
|
||||
@@ -12,15 +12,15 @@ export class Session implements ISession {
|
||||
private quest: Quest
|
||||
|
||||
constructor(
|
||||
{ completedStages }: ISession,
|
||||
{ completedEvents }: ISession,
|
||||
quest: IQuest,
|
||||
checker: IFileExistenceChecker
|
||||
) {
|
||||
this.completed = completedStages
|
||||
this.completed = completedEvents
|
||||
this.quest = new Quest(quest, checker)
|
||||
}
|
||||
|
||||
get completedStages() {
|
||||
get completedEvents() {
|
||||
return this.completed
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ export class Session implements ISession {
|
||||
}
|
||||
|
||||
async runCommand(command: ICommand) {
|
||||
const stageId = await this.quest.findSatisfiedStage(command, this.completed)
|
||||
const stageId = await this.quest.findSatisfiedEvent(command, this.completed)
|
||||
if (stageId) {
|
||||
this.complete(stageId)
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ export interface ICommand {
|
||||
}
|
||||
|
||||
export interface ISession {
|
||||
completedStages: string[]
|
||||
completedEvents: string[]
|
||||
}
|
||||
@@ -66,19 +66,19 @@ const quest: IQuest = {
|
||||
describe('exceptions', () => {
|
||||
it('should return the stage exception', async () => {
|
||||
const session = new Session(
|
||||
{ completedStages: [] },
|
||||
{ completedEvents: [] },
|
||||
quest,
|
||||
new MockFileChecker()
|
||||
)
|
||||
expect(await session.runCommand({ command: 'ls' })).toBe('exception1')
|
||||
await session.runCommand({ command: 'echo start' })
|
||||
console.log('completed', session.completedStages)
|
||||
console.log('completed', session.completedEvents)
|
||||
expect(await session.runCommand({ command: 'ls' })).toBe('stage2')
|
||||
})
|
||||
|
||||
it('should return the catch all exception', async () => {
|
||||
const session = new Session(
|
||||
{ completedStages: [] },
|
||||
{ completedEvents: [] },
|
||||
quest,
|
||||
new MockFileChecker()
|
||||
)
|
||||
@@ -89,7 +89,7 @@ describe('exceptions', () => {
|
||||
|
||||
it('should return the global exception', async () => {
|
||||
const session = new Session(
|
||||
{ completedStages: [] },
|
||||
{ completedEvents: [] },
|
||||
quest,
|
||||
new MockFileChecker()
|
||||
)
|
||||
|
||||
@@ -49,7 +49,7 @@ describe('Session', () => {
|
||||
it('should return active stages', () => {
|
||||
const session = new Session(
|
||||
{
|
||||
completedStages: [],
|
||||
completedEvents: [],
|
||||
},
|
||||
quest,
|
||||
new MockFileChecker()
|
||||
@@ -69,7 +69,7 @@ describe('Session', () => {
|
||||
it('should run command', async () => {
|
||||
const session = new Session(
|
||||
{
|
||||
completedStages: [],
|
||||
completedEvents: [],
|
||||
},
|
||||
quest,
|
||||
new MockFileChecker()
|
||||
@@ -96,7 +96,7 @@ describe('Session', () => {
|
||||
it('should return all responses', () => {
|
||||
const session = new Session(
|
||||
{
|
||||
completedStages: ['stage1'],
|
||||
completedEvents: ['stage1'],
|
||||
},
|
||||
quest,
|
||||
new MockFileChecker()
|
||||
|
||||
Reference in new issue
Block a user