|
|
@@ -6,6 +6,7 @@ import EntityManager from '~/services/data/entityManager'
|
|
|
import ApiResource from '~/models/ApiResource'
|
|
|
import ApiModel from '~/models/ApiModel'
|
|
|
import ApiRequestService from '~/services/data/apiRequestService'
|
|
|
+import { IdField } from '~/models/decorators'
|
|
|
|
|
|
class DummyApiResource extends ApiResource {
|
|
|
static entity = 'dummyResource'
|
|
|
@@ -367,9 +368,9 @@ describe('fetch', () => {
|
|
|
describe('fetchCollection', () => {
|
|
|
test('simple call', async () => {
|
|
|
const collection = {
|
|
|
- '@type': 'hydra:Collection',
|
|
|
- 'hydra:totalItems': 3,
|
|
|
- 'hydra:member': [{ id: 1 }, { id: 2 }, { id: 3 }],
|
|
|
+ '@type': 'Collection',
|
|
|
+ 'totalItems': 3,
|
|
|
+ 'member': [{ id: 1 }, { id: 2 }, { id: 3 }],
|
|
|
}
|
|
|
|
|
|
// @ts-ignore
|
|
|
@@ -436,9 +437,9 @@ describe('fetchCollection', () => {
|
|
|
|
|
|
test('with a parent', async () => {
|
|
|
const collection = {
|
|
|
- '@type': 'hydra:Collection',
|
|
|
- 'hydra:totalItems': 3,
|
|
|
- 'hydra:member': [{ id: 1 }, { id: 2 }, { id: 3 }],
|
|
|
+ '@type': 'Collection',
|
|
|
+ 'totalItems': 3,
|
|
|
+ 'member': [{ id: 1 }, { id: 2 }, { id: 3 }],
|
|
|
}
|
|
|
|
|
|
// @ts-ignore
|
|
|
@@ -469,9 +470,9 @@ describe('fetchCollection', () => {
|
|
|
|
|
|
test('with a query', async () => {
|
|
|
const collection = {
|
|
|
- '@type': 'hydra:Collection',
|
|
|
- 'hydra:totalItems': 3,
|
|
|
- 'hydra:member': [{ id: 1 }, { id: 2 }, { id: 3 }],
|
|
|
+ '@type': 'Collection',
|
|
|
+ 'totalItems': 3,
|
|
|
+ 'member': [{ id: 1 }, { id: 2 }, { id: 3 }],
|
|
|
}
|
|
|
|
|
|
const query = vi.fn()
|
|
|
@@ -588,7 +589,7 @@ describe('persist', () => {
|
|
|
// entityManager.cast = vi.fn((model: typeof ApiResource, entity: ApiResource): ApiResource => entity)
|
|
|
|
|
|
// @ts-ignore
|
|
|
- apiRequestService.put = vi.fn((url, data) => props)
|
|
|
+ apiRequestService.patch = vi.fn((url, data) => props)
|
|
|
|
|
|
// @ts-ignore
|
|
|
entityManager.newInstance = vi.fn((model, response) => {
|
|
|
@@ -609,7 +610,7 @@ describe('persist', () => {
|
|
|
|
|
|
const result = await entityManager.persist(entity)
|
|
|
|
|
|
- expect(apiRequestService.put).toHaveBeenCalledWith(
|
|
|
+ expect(apiRequestService.patch).toHaveBeenCalledWith(
|
|
|
'api/dummyModel/1',
|
|
|
{
|
|
|
id: 1,
|
|
|
@@ -670,7 +671,6 @@ describe('patch', () => {
|
|
|
describe('delete', () => {
|
|
|
test('delete non persisted entity', () => {
|
|
|
const entity = new DummyApiModel()
|
|
|
- entity.isNew = vi.fn(() => true)
|
|
|
entity.id = 'tmp123'
|
|
|
|
|
|
// @ts-ignore
|