2020-08-05 21:09:04 +02:00
|
|
|
/* eslint-disable */
|
|
|
|
|
2020-04-09 15:59:54 +02:00
|
|
|
import React from 'react';
|
2020-08-05 21:09:04 +02:00
|
|
|
import {isApiResponseValid} from '../../src/utils/WebData';
|
2020-04-09 15:59:54 +02:00
|
|
|
|
2020-08-05 21:09:04 +02:00
|
|
|
const fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
|
2020-04-09 15:59:54 +02:00
|
|
|
|
|
|
|
test('isRequestResponseValid', () => {
|
2020-08-05 21:09:04 +02:00
|
|
|
let json = {
|
|
|
|
error: 0,
|
|
|
|
data: {},
|
|
|
|
};
|
|
|
|
expect(isApiResponseValid(json)).toBeTrue();
|
|
|
|
json = {
|
|
|
|
error: 1,
|
|
|
|
data: {},
|
|
|
|
};
|
|
|
|
expect(isApiResponseValid(json)).toBeTrue();
|
|
|
|
json = {
|
|
|
|
error: 50,
|
|
|
|
data: {},
|
|
|
|
};
|
|
|
|
expect(isApiResponseValid(json)).toBeTrue();
|
|
|
|
json = {
|
|
|
|
error: 50,
|
|
|
|
data: {truc: 'machin'},
|
|
|
|
};
|
|
|
|
expect(isApiResponseValid(json)).toBeTrue();
|
|
|
|
json = {
|
|
|
|
message: 'coucou',
|
|
|
|
};
|
|
|
|
expect(isApiResponseValid(json)).toBeFalse();
|
|
|
|
json = {
|
|
|
|
error: 'coucou',
|
|
|
|
data: {truc: 'machin'},
|
|
|
|
};
|
|
|
|
expect(isApiResponseValid(json)).toBeFalse();
|
|
|
|
json = {
|
|
|
|
error: 0,
|
|
|
|
data: 'coucou',
|
|
|
|
};
|
|
|
|
expect(isApiResponseValid(json)).toBeFalse();
|
|
|
|
json = {
|
|
|
|
error: 0,
|
|
|
|
};
|
|
|
|
expect(isApiResponseValid(json)).toBeFalse();
|
2020-04-09 15:59:54 +02:00
|
|
|
});
|