|
| 1 | +/* |
| 2 | +* Validation test file |
| 3 | +* Description: This file contains tests which check if any modifications |
| 4 | +* make the new code incompatible with the old one. |
| 5 | +*/ |
| 6 | + |
| 7 | +// Importing the normalize function |
| 8 | +import normalize from '../index'; |
| 9 | +// Importing mocha and chai for the tests |
| 10 | +import { expect } from 'chai'; |
| 11 | +import 'mocha'; |
| 12 | + |
| 13 | +// Creating the test set |
| 14 | +describe('normalize test', () => { |
| 15 | + it('should normalize when included relationship is null', () => { |
| 16 | + const test = { |
| 17 | + "data":[ |
| 18 | + { |
| 19 | + "id":"3", |
| 20 | + "type":"conversation", |
| 21 | + "attributes":{ |
| 22 | + "subject":"Test subject" |
| 23 | + }, |
| 24 | + "relationships":{ |
| 25 | + "last_message":{ |
| 26 | + "data":{ type: "people", id: "9" } |
| 27 | + } |
| 28 | + } |
| 29 | + }, |
| 30 | + ], |
| 31 | + "included": [], |
| 32 | + }; |
| 33 | + expect(() => normalize(test)).to.not.throw(); |
| 34 | + const normalized = normalize(test); |
| 35 | + expect(normalized).to.have.property('conversation'); |
| 36 | + }); |
| 37 | + it('should normalize when property "included" is undefined', () => { |
| 38 | + const test = { |
| 39 | + "data":[ |
| 40 | + { |
| 41 | + "id":"3", |
| 42 | + "type":"conversation", |
| 43 | + "attributes":{ |
| 44 | + "subject":"Test subject" |
| 45 | + }, |
| 46 | + "relationships":{ |
| 47 | + "last_message":{ |
| 48 | + "data":{ type: "people", id: "9" } |
| 49 | + } |
| 50 | + } |
| 51 | + }, |
| 52 | + ], |
| 53 | + }; |
| 54 | + expect(() => normalize(test)).to.not.throw(); |
| 55 | + const normalized = normalize(test); |
| 56 | + expect(normalized).to.have.property('conversation'); |
| 57 | + }); |
| 58 | + it('should normalize when property "included" is undefined and relationship is null', () => { |
| 59 | + const test = { |
| 60 | + "data":[ |
| 61 | + { |
| 62 | + "id":"3", |
| 63 | + "type":"conversation", |
| 64 | + "attributes":{ |
| 65 | + "subject":"Test subject" |
| 66 | + }, |
| 67 | + "relationships":{ |
| 68 | + "last_message":{ |
| 69 | + "data": null |
| 70 | + } |
| 71 | + } |
| 72 | + }, |
| 73 | + ], |
| 74 | + }; |
| 75 | + expect(() => normalize(test)).to.not.throw(); |
| 76 | + const normalized = normalize(test); |
| 77 | + expect(normalized).to.have.property('conversation'); |
| 78 | + }); |
| 79 | +}); |
0 commit comments