-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add models list test cases
- Loading branch information
1 parent
ecc95c7
commit d932adc
Showing
14 changed files
with
92 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
cortex-js/src/infrastructure/commanders/test/model-list.command.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { TestingModule } from '@nestjs/testing'; | ||
import { stubMethod } from 'hanbi'; | ||
import { CommandTestFactory } from 'nest-commander-testing'; | ||
import { CommandModule } from '@/command.module'; | ||
import { FileManagerService } from '@/file-manager/file-manager.service'; | ||
import { join } from 'path'; | ||
import { mkdirSync, rmSync, writeFileSync } from 'fs'; | ||
|
||
let commandInstance: TestingModule; | ||
|
||
beforeEach(async () => { | ||
commandInstance = await CommandTestFactory.createTestingCommand({ | ||
imports: [CommandModule], | ||
}) | ||
// .overrideProvider(LogService) | ||
// .useValue({}) | ||
.compile(); | ||
const fileService = | ||
commandInstance.resolve<FileManagerService>(FileManagerService); | ||
|
||
// Attempt to create test folder | ||
(await fileService).writeConfigFile({ | ||
dataFolderPath: join(__dirname, 'test_data'), | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
// Attempt to clean test folder | ||
try { | ||
await rmSync(join(__dirname, 'test_data'), { | ||
recursive: true, | ||
force: true, | ||
}); | ||
} catch (e) {} | ||
}); | ||
|
||
describe('models list returns array of models', () => { | ||
test('empty model list', async () => { | ||
const logMock = stubMethod(console, 'table'); | ||
|
||
await CommandTestFactory.run(commandInstance, ['models', 'list']); | ||
expect(logMock.firstCall?.args[0]).toBeInstanceOf(Array); | ||
expect(logMock.firstCall?.args[0].length).toBe(0); | ||
}); | ||
|
||
test('many models in the list', async () => { | ||
const logMock = stubMethod(console, 'table'); | ||
|
||
mkdirSync(join(__dirname, 'test_data', 'models'), { recursive: true }); | ||
writeFileSync( | ||
join(__dirname, 'test_data', 'models', 'test.yaml'), | ||
'model: test', | ||
'utf8', | ||
); | ||
|
||
await CommandTestFactory.run(commandInstance, ['models', 'list']); | ||
expect(logMock.firstCall?.args[0]).toBeInstanceOf(Array); | ||
expect(logMock.firstCall?.args[0].length).toBe(1); | ||
expect(logMock.firstCall?.args[0][0].id).toBe('test'); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
cortex-js/src/infrastructure/commanders/usecases/ps.cli.usecases.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
cortex-js/src/infrastructure/database/mysql-database.providers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
cortex-js/src/infrastructure/database/sqlite-database.providers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters