refactor: add new name "Event" for the set Stage and Exception

This commit is contained in:
Justin Lin committed 2025-04-21 11:58:05 +08:00
1 parent 6e804f0ed4
commit 2dc40a2254
5 files changed
+13 -13

No files matched your search

+1 -1
View File
@@ -37,7 +37,7 @@ export class Quest {
) )
} }
async findSatisfiedStage( async findSatisfiedEvent(
command: ICommand, command: ICommand,
completed: string[] completed: string[]
): Promise<string | null> { ): Promise<string | null> {
+4 -4
View File
@@ -12,15 +12,15 @@ export class Session implements ISession {
private quest: Quest private quest: Quest
constructor( constructor(
{ completedStages }: ISession, { completedEvents }: ISession,
quest: IQuest, quest: IQuest,
checker: IFileExistenceChecker checker: IFileExistenceChecker
) { ) {
this.completed = completedStages this.completed = completedEvents
this.quest = new Quest(quest, checker) this.quest = new Quest(quest, checker)
} }
get completedStages() { get completedEvents() {
return this.completed return this.completed
} }
@@ -33,7 +33,7 @@ export class Session implements ISession {
} }
async runCommand(command: ICommand) { async runCommand(command: ICommand) {
const stageId = await this.quest.findSatisfiedStage(command, this.completed) const stageId = await this.quest.findSatisfiedEvent(command, this.completed)
if (stageId) { if (stageId) {
this.complete(stageId) this.complete(stageId)
} }
+1 -1
View File
@@ -12,5 +12,5 @@ export interface ICommand {
} }
export interface ISession { export interface ISession {
completedStages: string[] completedEvents: string[]
} }
+4 -4
View File
@@ -66,19 +66,19 @@ const quest: IQuest = {
describe('exceptions', () => { describe('exceptions', () => {
it('should return the stage exception', async () => { it('should return the stage exception', async () => {
const session = new Session( const session = new Session(
{ completedStages: [] }, { completedEvents: [] },
quest, quest,
new MockFileChecker() new MockFileChecker()
) )
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.completedStages) console.log('completed', session.completedEvents)
expect(await session.runCommand({ command: 'ls' })).toBe('stage2') expect(await session.runCommand({ command: 'ls' })).toBe('stage2')
}) })
it('should return the catch all exception', async () => { it('should return the catch all exception', async () => {
const session = new Session( const session = new Session(
{ completedStages: [] }, { completedEvents: [] },
quest, quest,
new MockFileChecker() new MockFileChecker()
) )
@@ -89,7 +89,7 @@ describe('exceptions', () => {
it('should return the global exception', async () => { it('should return the global exception', async () => {
const session = new Session( const session = new Session(
{ completedStages: [] }, { completedEvents: [] },
quest, quest,
new MockFileChecker() new MockFileChecker()
) )
+3 -3
View File
@@ -49,7 +49,7 @@ describe('Session', () => {
it('should return active stages', () => { it('should return active stages', () => {
const session = new Session( const session = new Session(
{ {
completedStages: [], completedEvents: [],
}, },
quest, quest,
new MockFileChecker() new MockFileChecker()
@@ -69,7 +69,7 @@ describe('Session', () => {
it('should run command', async () => { it('should run command', async () => {
const session = new Session( const session = new Session(
{ {
completedStages: [], completedEvents: [],
}, },
quest, quest,
new MockFileChecker() new MockFileChecker()
@@ -96,7 +96,7 @@ describe('Session', () => {
it('should return all responses', () => { it('should return all responses', () => {
const session = new Session( const session = new Session(
{ {
completedStages: ['stage1'], completedEvents: ['stage1'],
}, },
quest, quest,
new MockFileChecker() new MockFileChecker()