|
|
@@ -1,9 +1,10 @@
|
|
|
-import { describe, test, expect } from 'vitest'
|
|
|
+import { describe, test, it, expect } from 'vitest'
|
|
|
import EntityManager from "~/services/data/entityManager";
|
|
|
import ApiResource from "~/models/ApiResource";
|
|
|
import ApiModel from "~/models/ApiModel";
|
|
|
import ApiRequestService from "~/services/data/apiRequestService";
|
|
|
import {Element, Repository} from "pinia-orm";
|
|
|
+import models from "~/models/models";
|
|
|
|
|
|
|
|
|
|
|
|
@@ -22,18 +23,32 @@ let _console: any = {
|
|
|
'error': console.error,
|
|
|
}
|
|
|
|
|
|
+vi.mock("~/models/models", async () => {
|
|
|
+ class MyModel {
|
|
|
+ static entity = 'myModel'
|
|
|
+ }
|
|
|
+
|
|
|
+ const models: Record<string, any> = {'myModel': MyModel}
|
|
|
+
|
|
|
+ return {
|
|
|
+ default: models
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
let apiRequestService: ApiRequestService
|
|
|
let entityManager: EntityManager
|
|
|
let repo: Repository<ApiResource>
|
|
|
+let _getRepo: (model: typeof ApiResource) => Repository<ApiResource>
|
|
|
|
|
|
beforeEach(() => {
|
|
|
// @ts-ignore
|
|
|
- apiRequestService = vi.fn() as ApiRequestService
|
|
|
-
|
|
|
- entityManager = new EntityManager(apiRequestService)
|
|
|
+ repo = vi.fn() as Repository<ApiResource>
|
|
|
|
|
|
// @ts-ignore
|
|
|
- repo = vi.fn() as Repository<ApiResource>
|
|
|
+ apiRequestService = vi.fn() as ApiRequestService
|
|
|
+ _getRepo = vi.fn((model: typeof ApiResource) => repo)
|
|
|
+
|
|
|
+ entityManager = new EntityManager(apiRequestService, _getRepo)
|
|
|
})
|
|
|
|
|
|
afterEach(() => {
|
|
|
@@ -44,7 +59,11 @@ afterEach(() => {
|
|
|
})
|
|
|
|
|
|
describe('getRepository', () => {
|
|
|
- // TODO: à revoir
|
|
|
+ test('simple call', () => {
|
|
|
+ entityManager.getRepository(DummyApiResource)
|
|
|
+
|
|
|
+ expect(_getRepo).toHaveBeenCalledWith(DummyApiResource)
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('cast', () => {
|
|
|
@@ -57,7 +76,9 @@ describe('cast', () => {
|
|
|
})
|
|
|
|
|
|
describe('getModelFor', () => {
|
|
|
- // TODO: à revoir
|
|
|
+ test('simple call', () => {
|
|
|
+ expect(entityManager.getModelFor('myModel').entity).toEqual('myModel')
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('getModelFromIri', () => {
|
|
|
@@ -70,7 +91,7 @@ describe('getModelFromIri', () => {
|
|
|
|
|
|
expect(result).toEqual(DummyApiResource)
|
|
|
})
|
|
|
- test('invalid Iri', () => {
|
|
|
+ test('invalide Iri', () => {
|
|
|
expect(() => entityManager.getModelFromIri('/invalid')).toThrowError('cannot parse the IRI')
|
|
|
})
|
|
|
})
|