Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Commit

Permalink
W.I.P.
Browse files Browse the repository at this point in the history
  • Loading branch information
pierce-h committed Aug 24, 2020
1 parent 74da599 commit c4d0a43
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/core/test-app/runner/validate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "@shipengine/connect-sdk/lib/internal/common";
import { NewLabel } from "@shipengine/connect-sdk/lib/internal/carriers/documents/new-label";
import { _internal } from "@shipengine/connect-sdk/lib/internal/common/utils";
import { NewPackage } from "@shipengine/connect-sdk/lib/internal/carriers/packages/new-package";

const joiOptions = {
abortEarly: false,
Expand Down Expand Up @@ -58,7 +59,14 @@ const createShipmentInternationalTestParamsSchema = Joi.object({

const CreateShipmentMultiPackageTestParamsSchema = Joi.object({
...baseTestParamValidations,
...{}
...{
deliveryServiceName: Joi.string().optional(),
deliveryConfirmationName: Joi.string().optional(),
shipFrom: AddressWithContactInfo[_internal].schema.optional(),
shipTo: AddressWithContactInfo[_internal].schema.optional(),
shipDateTime: DateTimeZone[_internal].schema.optional(),
packages: Joi.array().min(1).items(NewPackage[_internal].schema).optional()
}
})

const CreateShipmentWithInsuranceTestParamsSchema = Joi.object({
Expand Down
251 changes: 251 additions & 0 deletions test/specs/core/test-app/runner/validate-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,131 @@ describe("validateConfig", () => {
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package.connectArgs must be of type object");
});

it("validates that deliveryServiceName is a string", () => {
const config = {
tests: {
createShipment_multi_package: {
deliveryServiceName: 123
}
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package.deliveryServiceName must be a string");
});

it("validates that deliveryConfirmationName is a string", () => {
const config = {
tests: {
createShipment_multi_package: {
deliveryConfirmationName: 123
}
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package.deliveryConfirmationName must be a string");
});

it("validates that shipFrom is an address object", () => {
const config = {
tests: {
createShipment_multi_package: {
shipFrom: "invalid"
}
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package.shipFrom must be of type object");
});

it("validates that shipTo is an address object", () => {
const config = {
tests: {
createShipment_multi_package: {
shipTo: "invalid"
}
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package.shipTo must be of type object");
});

it("validates that shipDateTime is a valid date time string", () => {
const config = {
tests: {
createShipment_multi_package: {
shipDateTime: "invalid"
}
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package.shipDateTime must be a complete ISO 8601 date/time with a time zone, like 2005-09-23T17:30:00+05:30");
});

it("validates that packages is an array of valid packages", () => {
const config = {
tests: {
createShipment_multi_package: {
packages: "invalid"
},
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package.packages must be an array");
});
});

describe("tests.createShipment_multi_package when given an array", () => {
Expand Down Expand Up @@ -1405,6 +1530,132 @@ describe("validateConfig", () => {
expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package[0].connectArgs must be of type object");
});

it("validates that deliveryServiceName is a string", () => {
const config = {
tests: {
createShipment_multi_package: [{
deliveryServiceName: 123
}],
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package[0].deliveryServiceName must be a string");
});

it("validates that deliveryConfirmationName is a string", () => {
const config = {
tests: {
createShipment_multi_package: [{
deliveryConfirmationName: 123
}],
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package[0].deliveryConfirmationName must be a string");
});

it("validates that shipFrom is an address object", () => {
const config = {
tests: {
createShipment_multi_package: [{
shipFrom: "invalid"
}],
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package[0].shipFrom must be of type object");
});

it("validates that shipTo is an address object", () => {
const config = {
tests: {
createShipment_multi_package: [{
shipTo: "invalid"
}],
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package[0].shipTo must be of type object");
});

it("validates that shipDateTime is a valid date time string", () => {
const config = {
tests: {
createShipment_multi_package: [{
shipDateTime: "invalid"
}],
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package[0].shipDateTime must be a complete ISO 8601 date/time with a time zone, like 2005-09-23T17:30:00+05:30");
});

it("validates that packages is an array of valid packages", () => {
const config = {
tests: {
createShipment_multi_package: [{
packages: "invalid"
}],
},
};
let result, errorResult;

try {
result = validateConfig(config);
}
catch (error) {
errorResult = error;
}

expect(result).to.be.undefined;
expect(errorResult.message).to.be.equal("tests.createShipment_multi_package[0].packages must be an array");
});
});

describe("tests.createShipment_with_insurance when given an object", () => {
Expand Down

0 comments on commit c4d0a43

Please sign in to comment.