Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WebData.test.js 1015B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { isApiResponseValid } from '../../src/utils/WebData';
  2. // eslint-disable-next-line no-unused-vars
  3. const fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
  4. test('isRequestResponseValid', () => {
  5. let json = {
  6. error: 0,
  7. data: {},
  8. };
  9. expect(isApiResponseValid(json)).toBeTrue();
  10. json = {
  11. error: 1,
  12. data: {},
  13. };
  14. expect(isApiResponseValid(json)).toBeTrue();
  15. json = {
  16. error: 50,
  17. data: {},
  18. };
  19. expect(isApiResponseValid(json)).toBeTrue();
  20. json = {
  21. error: 50,
  22. data: { truc: 'machin' },
  23. };
  24. expect(isApiResponseValid(json)).toBeTrue();
  25. json = {
  26. message: 'coucou',
  27. };
  28. expect(isApiResponseValid(json)).toBeFalse();
  29. json = {
  30. error: 'coucou',
  31. data: { truc: 'machin' },
  32. };
  33. expect(isApiResponseValid(json)).toBeFalse();
  34. json = {
  35. error: 0,
  36. data: 'coucou',
  37. };
  38. expect(isApiResponseValid(json)).toBeFalse();
  39. json = {
  40. error: 0,
  41. };
  42. expect(isApiResponseValid(json)).toBeFalse();
  43. });