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

Commit

Permalink
Merge branch 'master' into DX-225-cancel-multiple-shipments
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrauskopf committed Oct 14, 2020
2 parents 8eeb189 + 7a6a300 commit c7ee43f
Show file tree
Hide file tree
Showing 9 changed files with 432 additions and 6 deletions.
87 changes: 81 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"inquirer": "^7.3.3",
"joi": "17.2.1",
"js-yaml": "^3.14.0",
"json-schema": "^0.2.5",
"json-schema-faker": "^0.5.0-rcv.29",
"json5": "^2.1.3",
"lodash": "^4.17.20",
"luxon": "^1.24.1",
Expand Down Expand Up @@ -63,6 +65,7 @@
"@types/hapi__joi": "^17.1.6",
"@types/inquirer": "^7.3.0",
"@types/js-yaml": "^3.12.5",
"@types/json-schema-faker": "^0.5.1",
"@types/json5": "0.0.30",
"@types/luxon": "^1.25.0",
"@types/mocha": "^8.0.3",
Expand Down
2 changes: 2 additions & 0 deletions src/core/test-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { loadAndValidateConfig, LoadAndValidateConfigError } from "./test-app/ru
import { logFail, logPass, logStep } from "./utils/log-helpers";
import { logResults } from "./utils/log-helpers";
import {
ConnectionForm,
CreateShipmentInternational,
CreateShipmentDomestic,
CreateShipmentWithInsurance,
Expand Down Expand Up @@ -157,6 +158,7 @@ function registerTestSuiteModules(app: SdkApp): RegisteredTestSuiteModules {
// cancelPickups: [CancelPickupsTestSuite],
cancelShipments: [CancelShipmentsSingle, CancelShipmentsMultiple],
// createManifest: [CreateManifestTestSuite],
connectionForm: [ConnectionForm],
createShipment: [
CreateShipmentInternational,
CreateShipmentDomestic,
Expand Down
2 changes: 2 additions & 0 deletions src/core/test-app/runner/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable camelcase */

import { ConnectionFormConfigOptions } from "./config/connect-all-fields";
import { CreateShipmentInternationalConfigOptions } from "./config/create-shipment-international";
import { CreateShipmentDomesticConfigOptions } from "./config/create-shipment-domestic";
import { CreateShipmentMultiPackageConfigOptions } from './config/create-shipment-multipackage';
Expand All @@ -19,6 +20,7 @@ import { CancelPickupsSameDayConfigOptions } from './config/cancel-pickups-same-
export interface TestsConfig {
cancelShipments_single?: CancelShipmentsSingleConfigOptions | [CancelShipmentsSingleConfigOptions];
cancelShipments_multiple?: CancelShipmentsMultipleConfigOptions | [CancelShipmentsMultipleConfigOptions];
connectionForm?: ConnectionFormConfigOptions;
createShipment_domestic?:
| CreateShipmentDomesticConfigOptions
| [CreateShipmentDomesticConfigOptions];
Expand Down
9 changes: 9 additions & 0 deletions src/core/test-app/runner/config/connect-all-fields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BaseTestConfigOptions } from "./base-test-config-options";

export interface ConnectionFormTestParams {
connectionFormData: object;
}

export interface ConnectionFormConfigOptions
extends ConnectionFormTestParams,
BaseTestConfigOptions {}
8 changes: 8 additions & 0 deletions src/core/test-app/runner/validate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const baseTestParamValidations = {
timeout: Joi.number().optional(),
};

const connectionFormTestParamsSchema = Joi.object({
connectionFormData: Joi.object().keys().unknown(),
});

const createShipmentReturnTestParamsSchema = Joi.object({
...baseTestParamValidations,
...{
Expand Down Expand Up @@ -289,6 +293,10 @@ const TrackShipmentReturnSchema = Joi.object({
});

const testsSchema = Joi.object({
connect_all_fields: Joi.alternatives().conditional(Joi.array(), {
then: Joi.array().items(connectionFormTestParamsSchema),
otherwise: connectionFormTestParamsSchema,
}),
createShipment_return: Joi.alternatives().conditional(Joi.array(), {
then: Joi.array().items(createShipmentReturnTestParamsSchema),
otherwise: createShipmentReturnTestParamsSchema,
Expand Down
98 changes: 98 additions & 0 deletions src/core/test-app/tests/connect-all-fields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import jsf from 'json-schema-faker';
import { JSONSchema6 } from 'json-schema';
import { CarrierApp } from "@shipengine/connect-sdk/lib/internal";
import Suite from "../runner/suite";
import {
ConnectionFormConfigOptions,
ConnectionFormTestParams,
} from "../runner/config/connect-all-fields";
import reduceDefaultsWithConfig from '../utils/reduce-defaults-with-config';
import objectToTestTitle from '../utils/object-to-test-title';
import Test from '../runner/test';
import { v4 } from 'uuid';

interface TestArgs {
title: string;
methodArgs: ConnectionFormTestParams;
config: unknown;
}

interface FormDef {
dataSchema: JSONSchema6
}

export class ConnectionForm extends Suite {
title = "connect_all_fields";

private buildFormData(connectionForm: FormDef) {
const fakeData = jsf.generate(connectionForm) as FormDef;
return fakeData.dataSchema;
}

buildTestArg(
config: ConnectionFormConfigOptions,
): TestArgs | undefined {

const carrierApp = this.app as CarrierApp;

// Parse and Set Sensible defaults, merge in connects args
const defaults = {
...this.buildFormData(carrierApp.connectionForm),
...this.options.staticRootConfig.connectArgs
} as ConnectionFormTestParams;

// Merge default data + connects args, and user-provided config, in that order
const testParams = reduceDefaultsWithConfig<
ConnectionFormTestParams
>(defaults, config.connectionFormData ? config.connectionFormData : {});

const title = config.expectedErrorMessage
? `it raises an error when creating a connection form with ${objectToTestTitle(
testParams,
)}`
: `it validates the connection form with ${objectToTestTitle(
testParams,
)}`;

return {
title,
methodArgs: testParams,
config,
};
}

buildTestArgs(): Array<TestArgs | undefined> {
if (Array.isArray(this.config)) {
return this.config.map((config: ConnectionFormConfigOptions) => {
return this.buildTestArg(config);
});
}
const config = this.config as ConnectionFormConfigOptions;
return [this.buildTestArg(config)];
}

tests(): Test[] {
const testArgs = this.buildTestArgs().filter((args) => args !== undefined) as TestArgs[];

return testArgs.map((testArg) => {
return this.test(
testArg.title,
testArg.methodArgs,
testArg.config,
async () => {
const carrierApp = this.app as CarrierApp;
const transaction = {
id: v4(),
session: {},
};

if (!carrierApp.connect) {
throw new Error("connect is not implemented");
}

await carrierApp.connect(transaction, testArg.methodArgs);
}
);
});
}
}
1 change: 1 addition & 0 deletions src/core/test-app/tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./cancel-shipments-single";
export * from "./cancel-shipments-multiple";
export * from "./connect-all-fields";
export * from "./cancel-pickups-next-day"
export * from "./cancel-pickups-same-day"
export * from "./create-shipment-domestic";
Expand Down
Loading

0 comments on commit c7ee43f

Please sign in to comment.