urlOptionsBuilder.spec.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import UrlOptionsBuilder from '~/services/connection/urlOptionsBuilder'
  2. import {QUERY_TYPE} from '~/types/enums'
  3. import {DataProviderArgs} from "~/types/interfaces";
  4. describe('build()', () => {
  5. it('should return an array with options URL image at the end', () => {
  6. const args: DataProviderArgs = {
  7. type: QUERY_TYPE.IMAGE,
  8. imgArgs: {
  9. id:1,
  10. height:100,
  11. width:100
  12. }
  13. }
  14. jest.useFakeTimers('modern');
  15. jest.setSystemTime(1585692000000);
  16. const options = UrlOptionsBuilder.build(args)
  17. expect(options.pop()).toEqual('1585692000000')
  18. })
  19. it('should return an array with options lists', () => {
  20. const args: DataProviderArgs = {
  21. type: QUERY_TYPE.MODEL,
  22. listArgs: {
  23. itemsPerPage:10,
  24. page:1,
  25. filters:[
  26. {key: 'name', value: 'Foo'},
  27. {key: 'givenName', value: 'Bar'}
  28. ]
  29. }
  30. }
  31. const options = UrlOptionsBuilder.build(args)
  32. expect(options.pop()).toEqual('givenName=Bar')
  33. expect(options.pop()).toEqual('name=Foo')
  34. expect(options.pop()).toEqual('page=1')
  35. expect(options.pop()).toEqual('itemsPerPage=10')
  36. })
  37. })