Vincent GUFFON 4 lat temu
rodzic
commit
594e6548e5

+ 36 - 0
tests/unit/services/connection/urlOptionsBuilder.spec.ts

@@ -0,0 +1,36 @@
+import UrlOptionsBuilder from '~/services/connection/urlOptionsBuilder'
+import {QUERY_TYPE} from '~/types/enums'
+import {DataProviderArgs} from "~/types/interfaces";
+
+describe('build()', () => {
+  it('should return an array with options URL image at the end', () => {
+    const args: DataProviderArgs = {
+      type: QUERY_TYPE.IMAGE,
+      imgArgs: {
+        id:1,
+        height:100,
+        width:100
+      }
+    }
+
+    jest.useFakeTimers('modern');
+    jest.setSystemTime(new Date(2020, 3, 1));
+
+    const options = UrlOptionsBuilder.build(args)
+    expect(options.pop()).toEqual('1585692000000')
+  })
+
+  it('should return an array with options lists', () => {
+    const args: DataProviderArgs = {
+      type: QUERY_TYPE.MODEL,
+      listArgs: {
+        itemsPerPage:10,
+        page:1
+      }
+    }
+
+    const options = UrlOptionsBuilder.build(args)
+    expect(options.pop()).toEqual('page=1')
+    expect(options.pop()).toEqual('itemsPerPage=10')
+  })
+})

+ 21 - 20
tests/unit/services/serializer/denormalizer/hydra.spec.ts

@@ -33,25 +33,26 @@ describe('denormalize()', () => {
     }
 
     expect(Hydra.denormalize(serverResponse)).toStrictEqual<AnyJson>({
-      '@context': '/api/contexts/Access',
-      '@id': '/api/accesses/7351',
-      '@type': 'Access',
-      'hydra:itemPosition': 1,
-      'hydra:next': '/api/organizations?page=2',
-      'hydra:previous': '/api/organizations?page=1',
-      'hydra:totalItems': 20,
-      id: 7351,
-      itemPosition: 1,
-      next: 'organizations?page=2',
-      organization: '/api/organizations/37306',
-      person: {
-        '@type': 'Person',
-        givenName: 'Patrick',
-        id: 11344,
-        name: 'BRUEL'
+      "data": {
+        "@context": "/api/contexts/Access",
+        "@id": "/api/accesses/7351",
+        "@type": "Access",
+        "hydra:itemPosition": 1,
+        "hydra:next": "/api/organizations?page=2",
+        "hydra:previous": "/api/organizations?page=1",
+        "hydra:totalItems": 20,
+        "id": 7351,
+        "organization": "/api/organizations/37306",
+        "person": {
+          "@type": "Person",
+          "givenName": "Patrick",
+          "id": 11344,
+          "name": "BRUEL"
+        }
       },
-      previous: 'organizations?page=1',
-      totalItems: 20
+      "metadata": {
+        "type": 0
+      }
     })
   })
 
@@ -99,7 +100,7 @@ describe('denormalize()', () => {
     }
 
     const response = Hydra.denormalize(serverResponse)
-    expect(JSON.stringify(response)).toEqual(JSON.stringify([
+    expect(JSON.stringify(response)).toEqual(JSON.stringify({"data":[
       {
         '@id': '/api/accesses/7351',
         organization: '/api/organizations/37306',
@@ -124,7 +125,7 @@ describe('denormalize()', () => {
             givenName: 'George'
           }
       }
-    ]
+    ], 'metadata':{'type':1}}
     ))
   })
 })

+ 0 - 8
tests/unit/services/utils/apiError.spec.ts

@@ -1,8 +0,0 @@
-import ApiError from '~/services/exception/apiError'
-
-describe('getStatus()', () => {
-  it('should return the status code', () => {
-    const apiError = new ApiError(404, 'not found')
-    expect(apiError.getStatus()).toEqual(404)
-  })
-})

+ 47 - 0
tests/unit/services/utils/typesTesting.spec.ts

@@ -0,0 +1,47 @@
+import {DataPersisterArgs, DataProviderArgs} from "~/types/interfaces";
+import {QUERY_TYPE} from "~/types/enums";
+import TypesTesting from "~/services/utils/typesTesting";
+
+describe('isDataProviderArgs()', () => {
+  it('should return true if data is DataProviderArgs', () => {
+    const args:DataProviderArgs = {
+      type: QUERY_TYPE.MODEL,
+      listArgs: {
+        itemsPerPage: 10,
+        page: 1
+      }
+    }
+    expect(TypesTesting.isDataProviderArgs(args)).toBeTruthy()
+  })
+
+  it('should return false if data is not a DataProviderArgs', () => {
+    const args:DataPersisterArgs = {
+      type: QUERY_TYPE.MODEL,
+      data: {
+      }
+    }
+    expect(TypesTesting.isDataProviderArgs(args)).toBeFalsy()
+  })
+})
+
+describe('isDataPersisterArgs()', () => {
+  it('should return true if data is DataPersisterArgs', () => {
+    const args:DataPersisterArgs = {
+      type: QUERY_TYPE.MODEL,
+      data: {
+      }
+    }
+    expect(TypesTesting.isDataPersisterArgs(args)).toBeTruthy()
+  })
+
+  it('should return false if data is not a DataPersisterArgs', () => {
+    const args:DataProviderArgs = {
+      type: QUERY_TYPE.MODEL,
+      listArgs: {
+        itemsPerPage: 10,
+        page: 1
+      }
+    }
+    expect(TypesTesting.isDataPersisterArgs(args)).toBeFalsy()
+  })
+})