|
|
@@ -50,13 +50,13 @@ const _console: any = {
|
|
|
|
|
|
vi.mock('~/models/models', async () => {
|
|
|
class MyModel {
|
|
|
- static entity = 'myModel'
|
|
|
+ static entity = 'my-model'
|
|
|
}
|
|
|
|
|
|
- const models: Record<string, any> = { myModel: MyModel }
|
|
|
+ const modelsIndex: Record<string, any> = { 'my-model': () => MyModel }
|
|
|
|
|
|
return {
|
|
|
- default: models,
|
|
|
+ default: modelsIndex,
|
|
|
}
|
|
|
})
|
|
|
|
|
|
@@ -134,27 +134,35 @@ describe('cast', () => {
|
|
|
})
|
|
|
|
|
|
describe('getModelFor', () => {
|
|
|
- test('simple call', () => {
|
|
|
- expect(entityManager.getModelFor('myModel').entity).toEqual('myModel')
|
|
|
+ test('simple call', async () => {
|
|
|
+ const model = await entityManager.getModelFor('my-model')
|
|
|
+ expect(model!.entity).toEqual('my-model')
|
|
|
+ })
|
|
|
+ test('non existing model', async () => {
|
|
|
+ expect(
|
|
|
+ async () => await entityManager.getModelFor('non-existing-model'),
|
|
|
+ ).rejects.toThrowError(
|
|
|
+ "No model found for entity name 'non-existing-model'",
|
|
|
+ )
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('getModelFromIri', () => {
|
|
|
- test('simple call', () => {
|
|
|
+ test('simple call', async () => {
|
|
|
// @ts-ignore
|
|
|
- entityManager.getModelFor = vi.fn((entityName: string) =>
|
|
|
- entityName === 'dummy' ? DummyApiResource : null,
|
|
|
+ entityManager.getModelFor = vi.fn(
|
|
|
+ async (entityName: string) => DummyApiResource,
|
|
|
)
|
|
|
|
|
|
// @ts-ignore
|
|
|
- const result = entityManager.getModelFromIri('/api/dummy/123')
|
|
|
-
|
|
|
+ const result = await entityManager.getModelFromIri('/api/dummy/123')
|
|
|
+ console.log(result)
|
|
|
expect(result).toEqual(DummyApiResource)
|
|
|
})
|
|
|
test('invalide Iri', () => {
|
|
|
- expect(() => entityManager.getModelFromIri('/invalid')).toThrowError(
|
|
|
- 'cannot parse the IRI',
|
|
|
- )
|
|
|
+ expect(
|
|
|
+ async () => await entityManager.getModelFromIri('/invalid'),
|
|
|
+ ).rejects.toThrowError('cannot parse the IRI')
|
|
|
})
|
|
|
})
|
|
|
|