Skip to content

Commit

Permalink
Add unit testing for shipment validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jmccollum-woolpert committed Sep 17, 2024
1 parent 0a252bb commit cebd963
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions application/frontend/src/app/core/services/csv.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,53 @@ describe('CsvService', () => {
});
});

describe('Validate shipments', () => {
it('should not throw error on a valid shipment', () => {
const shipments = [{ label: 'test shipment' }];
const testMapping = { Label: 'label' };
const result = service.csvToShipments(shipments, testMapping);
expect(result.length).toBe(1);
expect(result[0].errors.length).toBe(0);
});

it('should not throw error on shipment with a valid load demand', () => {
const shipments = [
{
LoadDemand1Type: 'weight',
LoadDemand1Value: 10,
},
];
const testMapping = {
LoadDemand1Type: 'LoadDemand1Type',
LoadDemand1Value: 'LoadDemand1Value',
};
const result = service.csvToShipments(shipments, testMapping);
expect(result.length).toBe(1);
expect(result[0].errors.length).toBe(0);
});

it('should throw an error on shipment with an invalid load demand', () => {
const shipments = [
{
LoadDemand1Type: 'weight',
LoadDemand1Value: 'invalid',
},
{
LoadDemand1Type: 'weight',
LoadDemand1Value: 10.5,
},
];
const testMapping = {
LoadDemand1Type: 'LoadDemand1Type',
LoadDemand1Value: 'LoadDemand1Value',
};
const result = service.csvToShipments(shipments, testMapping);
expect(result.length).toBe(2);
expect(result[0].errors.length).toBe(1);
expect(result[1].errors.length).toBe(1);
});
});

describe('Validate vehicles', () => {
it('should throw no errors on a valid vehicle', () => {
const vehicles = [{ label: 'test vehicle' }];
Expand Down

0 comments on commit cebd963

Please sign in to comment.