浏览代码

fix unit tests

Olivier Massot 4 月之前
父节点
当前提交
3cc8904efe
共有 2 个文件被更改,包括 26 次插入25 次删除
  1. 3 2
      services/utils/urlUtils.ts
  2. 23 23
      tests/units/services/data/normalizer/hydraNormalizer.test.ts

+ 3 - 2
services/utils/urlUtils.ts

@@ -142,11 +142,12 @@ const UrlUtils = {
    * @see https://api-platform.com/docs/admin/handling-relations/
    */
   makeIRI(entity: string, id: number | string) {
+    const initialId = id
     if (_.isString(id)) {
       id = parseInt(id)
     }
-    if (!_.isNumber(id)) {
-      throw new TypeError('Invalid id : ' + id)
+    if (!_.isFinite(id)) {
+      throw new TypeError('Invalid id : ' + initialId)
     }
     return `/api/${entity}/${id}`
   },

+ 23 - 23
tests/units/services/data/normalizer/hydraNormalizer.test.ts

@@ -152,16 +152,16 @@ describe('getMetadata', () => {
     const data = {
       '@context': '/api/contexts/Foo',
       '@id': '/api/foo',
-      '@type': 'hydra:Collection',
-      'hydra:member': ['foo'],
-      'hydra:totalItems': 10,
-      'hydra:view': {
+      '@type': 'Collection',
+      'member': ['foo'],
+      'totalItems': 10,
+      'view': {
         '@id': '/api/foo?page=3',
-        '@type': 'hydra:PartialCollectionView',
-        'hydra:first': '/api/foo?page=1',
-        'hydra:last': '/api/foo?page=5',
-        'hydra:next': '/api/foo?page=4',
-        'hydra:previous': '/api/foo?page=2',
+        '@type': 'PartialCollectionView',
+        'first': '/api/foo?page=1',
+        'last': '/api/foo?page=5',
+        'next': '/api/foo?page=4',
+        'previous': '/api/foo?page=2',
       },
     }
 
@@ -169,23 +169,23 @@ describe('getMetadata', () => {
     const metadata = HydraNormalizer.getMetadata(data)
 
     expect(metadata.totalItems).toEqual(10)
-    expect(metadata.firstPage).toEqual(1)
-    expect(metadata.lastPage).toEqual(5)
-    expect(metadata.nextPage).toEqual(4)
-    expect(metadata.previousPage).toEqual(2)
+    expect(metadata.first).toEqual(1)
+    expect(metadata.last).toEqual(5)
+    expect(metadata.next).toEqual(4)
+    expect(metadata.previous).toEqual(2)
     expect(metadata.type).toEqual(METADATA_TYPE.COLLECTION)
   })
   test('With partial collection metadata', () => {
     const data = {
       '@context': '/api/contexts/Foo',
       '@id': '/api/foo',
-      '@type': 'hydra:Collection',
-      'hydra:member': ['foo'],
-      'hydra:totalItems': 10,
-      'hydra:view': {
+      '@type': 'Collection',
+      'member': ['foo'],
+      'totalItems': 10,
+      'view': {
         '@id': '/api/foo?page=3',
-        '@type': 'hydra:PartialCollectionView',
-        'hydra:first': '/api/foo?page=1',
+        '@type': 'PartialCollectionView',
+        'first': '/api/foo?page=1',
       },
     }
 
@@ -193,10 +193,10 @@ describe('getMetadata', () => {
     const metadata = HydraNormalizer.getMetadata(data)
 
     expect(metadata.totalItems).toEqual(10)
-    expect(metadata.firstPage).toEqual(1)
-    expect(metadata.lastPage).toEqual(1)
-    expect(metadata.nextPage).toEqual(undefined)
-    expect(metadata.previousPage).toEqual(undefined)
+    expect(metadata.first).toEqual(1)
+    expect(metadata.last).toEqual(1)
+    expect(metadata.next).toEqual(undefined)
+    expect(metadata.previous).toEqual(undefined)
   })
 
   test('With item metadata', () => {