Add scaffolding for sra-report collection unit tests

This commit is contained in:
Brandon Millman 2018-03-12 11:00:08 -07:00
parent df9e7385ad
commit b08374f0ba
15 changed files with 8028 additions and 11 deletions

View File

@ -6,9 +6,13 @@
"types": "lib/index.d.ts",
"scripts": {
"build:watch": "tsc -w",
"lint": "tslint --project . 'src/**/*.ts'",
"lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'",
"clean": "shx rm -rf lib",
"build": "tsc"
"build": "tsc",
"test": "run-s clean build copy_test_environments copy_test_fixtures run_mocha",
"copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures",
"copy_test_environments": "copyfiles -u 2 './test/environments/**/*.json' ./lib/test/environments",
"run_mocha": "mocha lib/test/**/*_test.js"
},
"bin": {
"sra-report": "lib/index.js"
@ -36,8 +40,19 @@
"devDependencies": {
"@0xproject/tslint-config": "^0.4.10",
"@types/lodash": "^4.14.86",
"@types/mocha": "^2.2.48",
"@types/nock": "^9.1.2",
"@types/node": "^8.0.53",
"@types/yargs": "^10.0.0",
"chai": "^4.0.1",
"chai-as-promised": "^7.1.0",
"chai-as-promised-typescript-typings": "^0.0.10",
"chai-typescript-typings": "^0.0.4",
"copyfiles": "^2.0.0",
"dirty-chai": "^2.0.1",
"mocha": "^4.0.1",
"nock": "^9.2.3",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
"tslint": "5.8.0",
"typescript": "2.7.1"

View File

@ -1,6 +1,27 @@
declare module 'dirty-chai';
declare module 'newman' {
// tslint:disable-next-line:completed-docs
export function run(options: any, callback?: () => void): void;
export interface NewmanRunSummary {
run: NewmanRun;
}
export interface NewmanRun {
executions: NewmanRunExecution[];
}
export interface NewmanRunExecution {
item: NewmanRunExecutionItem;
assertions: NewmanRunExecutionAssertion[];
}
export interface NewmanRunExecutionItem {
name: string;
}
export interface NewmanRunExecutionAssertion {
assertion: string;
error: NewmanRunExecutionAssertionError;
}
export interface NewmanRunExecutionAssertionError {
message: string;
}
export function run(options: any, callback?: (err: Error | null, summary: NewmanRunSummary) => void): void;
}
declare module '*.json' {

View File

@ -7,12 +7,11 @@ import * as _ from 'lodash';
import * as newman from 'newman';
import * as yargs from 'yargs';
import * as sraReportCollectionJSON from '../postman_configs/collections/sra_report.postman_collection.json';
import * as sraReportCollectionJSON from '../../postman_collections/sra_report.postman_collection.json';
import { postmanEnvironmentFactory } from './postman_environment_factory';
import { utils } from './utils';
const newmanRunAsync = promisify<void>(newman.run);
const DEFAULT_NETWORK_ID = 1;
const SUPPORTED_NETWORK_IDS = [1, 3, 4, 42];
@ -97,6 +96,6 @@ const mainAsync = async () => {
exportEnvironment: args.exportEnvironment,
...newmanReporterOptions,
};
await newmanRunAsync(newmanRunOptions);
await utils.newmanRunAsync(newmanRunOptions);
};
mainAsync().catch(utils.log);

View File

@ -1,5 +1,9 @@
import { promisify } from '@0xproject/utils';
import { NewmanRunSummary, run as newmanRun } from 'newman';
export const utils = {
log(...args: any[]): void {
console.log(...args); // tslint:disable-line:no-console
},
newmanRunAsync: promisify<NewmanRunSummary>(newmanRun),
};

View File

@ -0,0 +1,223 @@
{
"id": "f23e415f-99a8-4d47-8796-6400af77d85f",
"name": "SRA Report",
"values": [
{
"type": "any",
"value": "{\"id\":\"/Number\",\"type\":\"string\",\"pattern\":\"^\\\\d+(\\\\.\\\\d+)?$\"}",
"key": "NumberSchema"
},
{
"type": "any",
"value": "{\"id\":\"/Address\",\"type\":\"string\",\"pattern\":\"^0x[0-9a-f]{40}$\"}",
"key": "AddressSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/ECSignature\",\"properties\":{\"v\":{\"type\":\"number\",\"minimum\":27,\"maximum\":28},\"r\":{\"$ref\":\"/ECSignatureParameter\"},\"s\":{\"$ref\":\"/ECSignatureParameter\"}},\"required\":[\"v\",\"r\",\"s\"],\"type\":\"object\"}",
"key": "ECSignatureSchema"
},
{
"type": "any",
"value": "{\"id\":\"/ECSignatureParameter\",\"type\":\"string\",\"pattern\":\"^0[xX][0-9A-Fa-f]{64}$\"}",
"key": "ECSignatureParameterSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/IndexFilterValues\",\"additionalProperties\":{\"oneOf\":[{\"$ref\":\"/Number\"},{\"$ref\":\"/Address\"},{\"$ref\":\"/OrderHashSchema\"}]},\"type\":\"object\"}",
"key": "IndexFilterValuesSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/OrderCancellationRequests\",\"type\":\"array\",\"items\":{\"properties\":{\"order\":{\"$ref\":\"/Order\"},\"takerTokenCancelAmount\":{\"$ref\":\"/Number\"}},\"required\":[\"order\",\"takerTokenCancelAmount\"],\"type\":\"object\"}}",
"key": "OrderCancellationRequestsSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/OrderFillOrKillRequests\",\"type\":\"array\",\"items\":{\"properties\":{\"signedOrder\":{\"$ref\":\"/SignedOrder\"},\"fillTakerAmount\":{\"$ref\":\"/Number\"}},\"required\":[\"signedOrder\",\"fillTakerAmount\"],\"type\":\"object\"}}",
"key": "OrderFillOrKillRequestsSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/OrderFillRequests\",\"type\":\"array\",\"items\":{\"properties\":{\"signedOrder\":{\"$ref\":\"/SignedOrder\"},\"takerTokenFillAmount\":{\"$ref\":\"/Number\"}},\"required\":[\"signedOrder\",\"takerTokenFillAmount\"],\"type\":\"object\"}}",
"key": "OrderFillRequestsSchema"
},
{
"type": "any",
"value": "{\"id\":\"/OrderHashSchema\",\"type\":\"string\",\"pattern\":\"^0x[0-9a-fA-F]{64}$\"}",
"key": "OrderHashSchemaSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/Order\",\"properties\":{\"maker\":{\"$ref\":\"/Address\"},\"taker\":{\"$ref\":\"/Address\"},\"makerFee\":{\"$ref\":\"/Number\"},\"takerFee\":{\"$ref\":\"/Number\"},\"makerTokenAmount\":{\"$ref\":\"/Number\"},\"takerTokenAmount\":{\"$ref\":\"/Number\"},\"makerTokenAddress\":{\"$ref\":\"/Address\"},\"takerTokenAddress\":{\"$ref\":\"/Address\"},\"salt\":{\"$ref\":\"/Number\"},\"feeRecipient\":{\"$ref\":\"/Address\"},\"expirationUnixTimestampSec\":{\"$ref\":\"/Number\"},\"exchangeContractAddress\":{\"$ref\":\"/Address\"}},\"required\":[\"maker\",\"taker\",\"makerFee\",\"takerFee\",\"makerTokenAmount\",\"takerTokenAmount\",\"salt\",\"feeRecipient\",\"expirationUnixTimestampSec\",\"exchangeContractAddress\"],\"type\":\"object\"}",
"key": "OrderSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/SignedOrder\",\"allOf\":[{\"$ref\":\"/Order\"},{\"properties\":{\"ecSignature\":{\"$ref\":\"/ECSignature\"}},\"required\":[\"ecSignature\"]}]}",
"key": "SignedOrderSchema"
},
{
"type": "any",
"value": "{\"id\":\"/signedOrdersSchema\",\"type\":\"array\",\"items\":{\"$ref\":\"/SignedOrder\"}}",
"key": "signedOrdersSchemaSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/BlockParam\",\"oneOf\":[{\"type\":\"number\"},{\"enum\":[\"latest\",\"earliest\",\"pending\"]}]}",
"key": "BlockParamSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/BlockRange\",\"properties\":{\"fromBlock\":{\"$ref\":\"/BlockParam\"},\"toBlock\":{\"$ref\":\"/BlockParam\"}},\"type\":\"object\"}",
"key": "BlockRangeSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/Token\",\"properties\":{\"name\":{\"type\":\"string\"},\"symbol\":{\"type\":\"string\"},\"decimals\":{\"type\":\"number\"},\"address\":{\"$ref\":\"/Address\"}},\"required\":[\"name\",\"symbol\",\"decimals\",\"address\"],\"type\":\"object\"}",
"key": "TokenSchema"
},
{
"type": "any",
"value": "{\"id\":\"/JsNumber\",\"type\":\"number\",\"minimum\":0}",
"key": "JsNumberSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/TxData\",\"properties\":{\"from\":{\"$ref\":\"/Address\"},\"to\":{\"$ref\":\"/Address\"},\"value\":{\"oneOf\":[{\"$ref\":\"/Number\"},{\"$ref\":\"/JsNumber\"}]},\"gas\":{\"oneOf\":[{\"$ref\":\"/Number\"},{\"$ref\":\"/JsNumber\"}]},\"gasPrice\":{\"oneOf\":[{\"$ref\":\"/Number\"},{\"$ref\":\"/JsNumber\"}]},\"data\":{\"type\":\"string\",\"pattern\":\"^0x[0-9a-f]*$\"},\"nonce\":{\"type\":\"number\",\"minimum\":0}},\"required\":[\"from\"],\"type\":\"object\",\"additionalProperties\":false}",
"key": "TxDataSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiErrorResponse\",\"type\":\"object\",\"properties\":{\"code\":{\"type\":\"number\"},\"reason\":{\"type\":\"string\"},\"validationErrors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"field\":{\"type\":\"string\"},\"code\":{\"type\":\"number\"},\"reason\":{\"type\":\"string\"}},\"required\":[\"field\",\"code\",\"reason\"]}}},\"required\":[\"code\",\"reason\"]}",
"key": "RelayerApiErrorResponseSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiFeesPayload\",\"type\":\"object\",\"properties\":{\"exchangeContractAddress\":{\"$ref\":\"/Address\"},\"maker\":{\"$ref\":\"/Address\"},\"taker\":{\"$ref\":\"/Address\"},\"makerTokenAddress\":{\"$ref\":\"/Address\"},\"takerTokenAddress\":{\"$ref\":\"/Address\"},\"makerTokenAmount\":{\"$ref\":\"/Number\"},\"takerTokenAmount\":{\"$ref\":\"/Number\"},\"expirationUnixTimestampSec\":{\"$ref\":\"/Number\"},\"salt\":{\"$ref\":\"/Number\"}},\"required\":[\"exchangeContractAddress\",\"maker\",\"taker\",\"makerTokenAddress\",\"takerTokenAddress\",\"expirationUnixTimestampSec\",\"salt\"]}",
"key": "RelayerApiFeesPayloadSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiFeesResponse\",\"type\":\"object\",\"properties\":{\"makerFee\":{\"$ref\":\"/Number\"},\"takerFee\":{\"$ref\":\"/Number\"},\"feeRecipient\":{\"$ref\":\"/Address\"}},\"required\":[\"makerFee\",\"takerFee\",\"feeRecipient\"]}",
"key": "RelayerApiFeesResponseSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiOrderBookResponse\",\"type\":\"object\",\"properties\":{\"bids\":{\"$ref\":\"/signedOrdersSchema\"},\"asks\":{\"$ref\":\"/signedOrdersSchema\"}},\"required\":[\"bids\",\"asks\"]}",
"key": "RelayerApiOrderBookResponseSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiTokenPairsResponse\",\"type\":\"array\",\"items\":{\"properties\":{\"tokenA\":{\"$ref\":\"/RelayerApiTokenTradeInfo\"},\"tokenB\":{\"$ref\":\"/RelayerApiTokenTradeInfo\"}},\"required\":[\"tokenA\",\"tokenB\"],\"type\":\"object\"}}",
"key": "RelayerApiTokenPairsResponseSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiTokenTradeInfo\",\"type\":\"object\",\"properties\":{\"address\":{\"$ref\":\"/Address\"},\"minAmount\":{\"$ref\":\"/Number\"},\"maxAmount\":{\"$ref\":\"/Number\"},\"precision\":{\"type\":\"number\"}},\"required\":[\"address\"]}",
"key": "RelayerApiTokenTradeInfoSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiOrderbookChannelSubscribe\",\"type\":\"object\",\"properties\":{\"type\":{\"enum\":[\"subscribe\"]},\"channel\":{\"enum\":[\"orderbook\"]},\"requestId\":{\"type\":\"number\"},\"payload\":{\"$ref\":\"/RelayerApiOrderbookChannelSubscribePayload\"}},\"required\":[\"type\",\"channel\",\"requestId\",\"payload\"]}",
"key": "RelayerApiOrderbookChannelSubscribeSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiOrderbookChannelSubscribePayload\",\"type\":\"object\",\"properties\":{\"baseTokenAddress\":{\"$ref\":\"/Address\"},\"quoteTokenAddress\":{\"$ref\":\"/Address\"},\"snapshot\":{\"type\":\"boolean\"},\"limit\":{\"type\":\"number\"}},\"required\":[\"baseTokenAddress\",\"quoteTokenAddress\"]}",
"key": "RelayerApiOrderbookChannelSubscribePayloadSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiOrderbookChannelUpdate\",\"type\":\"object\",\"properties\":{\"type\":{\"enum\":[\"update\"]},\"channel\":{\"enum\":[\"orderbook\"]},\"requestId\":{\"type\":\"number\"},\"payload\":{\"$ref\":\"/SignedOrder\"}},\"required\":[\"type\",\"channel\",\"requestId\",\"payload\"]}",
"key": "RelayerApiOrderbookChannelUpdateSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiOrderbookChannelSnapshot\",\"type\":\"object\",\"properties\":{\"type\":{\"enum\":[\"snapshot\"]},\"channel\":{\"enum\":[\"orderbook\"]},\"requestId\":{\"type\":\"number\"},\"payload\":{\"$ref\":\"/RelayerApiOrderbookChannelSnapshotPayload\"}},\"required\":[\"type\",\"channel\",\"requestId\",\"payload\"]}",
"key": "RelayerApiOrderbookChannelSnapshotSchema"
},
{
"type": "any",
"value":
"{\"id\":\"/RelayerApiOrderbookChannelSnapshotPayload\",\"type\":\"object\",\"properties\":{\"bids\":{\"$ref\":\"/signedOrdersSchema\"},\"asks\":{\"$ref\":\"/signedOrdersSchema\"}},\"required\":[\"bids\",\"asks\"]}",
"key": "RelayerApiOrderbookChannelSnapshotPayloadSchema"
},
{
"type": "any",
"value":
"[\"NumberSchema\",\"AddressSchema\",\"ECSignatureSchema\",\"ECSignatureParameterSchema\",\"IndexFilterValuesSchema\",\"OrderCancellationRequestsSchema\",\"OrderFillOrKillRequestsSchema\",\"OrderFillRequestsSchema\",\"OrderHashSchemaSchema\",\"OrderSchema\",\"SignedOrderSchema\",\"signedOrdersSchemaSchema\",\"BlockParamSchema\",\"BlockRangeSchema\",\"TokenSchema\",\"JsNumberSchema\",\"TxDataSchema\",\"RelayerApiErrorResponseSchema\",\"RelayerApiFeesPayloadSchema\",\"RelayerApiFeesResponseSchema\",\"RelayerApiOrderBookResponseSchema\",\"RelayerApiTokenPairsResponseSchema\",\"RelayerApiTokenTradeInfoSchema\",\"RelayerApiOrderbookChannelSubscribeSchema\",\"RelayerApiOrderbookChannelSubscribePayloadSchema\",\"RelayerApiOrderbookChannelUpdateSchema\",\"RelayerApiOrderbookChannelSnapshotSchema\",\"RelayerApiOrderbookChannelSnapshotPayloadSchema\"]",
"key": "schemaKeys"
},
{
"type": "any",
"value": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"key": "tokenContractAddress1"
},
{
"type": "any",
"value": "0xe41d2489571d322189246dafa5ebde1f4699f498",
"key": "tokenContractAddress2"
},
{
"type": "any",
"value": "0x12459c951127e0c374ff9105dda097662a027093",
"key": "exchangeContractAddress"
},
{
"type": "any",
"value":
"{\"orderHash\":\"0xe91e990bab4c9c6bd60ff3673222390e3da8b7bd9a50eab98a8cb20723b24ee1\",\"exchangeContractAddress\":\"0x12459c951127e0c374ff9105dda097662a027093\",\"maker\":\"0x93690d55b14d701c259ba7960395c095aa52c3a8\",\"taker\":\"0x0000000000000000000000000000000000000000\",\"makerTokenAddress\":\"0x2956356cd2a2bf3202f771f50d3d14a367b48070\",\"takerTokenAddress\":\"0x0abdace70d3790235af448c88547603b945604ea\",\"feeRecipient\":\"0xa258b39954cef5cb142fd567a46cddb31a670124\",\"makerTokenAmount\":\"2926675830000000000\",\"takerTokenAmount\":\"24386933000000000000000\",\"makerFee\":\"18419638100000000000\",\"takerFee\":\"35812978500000000000\",\"expirationUnixTimestampSec\":\"9223372036854775807\",\"salt\":\"89583415499996246176114840147523733506098603782358761236056286417408784066968\",\"ecSignature\":{\"r\":\"0x32eb5bbf713210274ddd885e6b555699bc0189676ff73a4dc98c4cac41d3a6a6\",\"s\":\"0x193eb9440df49dc7817b6142c0be021cd1f9fc0916d86c7b49e9e07a402f3645\",\"v\":28}}",
"key": "order"
},
{
"type": "any",
"value": "0x93690d55b14d701c259ba7960395c095aa52c3a8",
"key": "orderMaker"
},
{
"type": "any",
"value": "0x0000000000000000000000000000000000000000",
"key": "orderTaker"
},
{
"type": "any",
"value": "0xa258b39954cef5cb142fd567a46cddb31a670124",
"key": "orderFeeRecipient"
},
{
"type": "any",
"value": "0xe91e990bab4c9c6bd60ff3673222390e3da8b7bd9a50eab98a8cb20723b24ee1",
"key": "orderHash"
},
{
"type": "any",
"value": "https://example.com",
"key": "url"
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2018-03-10T23:53:03.913Z",
"_postman_exported_using": "Newman/3.9.3"
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,30 @@
[
{
"tokenA": {
"address": "4a6b4ccb1b6faa2625fe562bdd9a23260359",
"minAmount": "1",
"maxAmount": "999999999999999999999",
"precision": 8
},
"tokenB": {
"address": "0x01b3ec4aae1b8729529beb4965f27d008788b0eb",
"minAmount": "1",
"maxAmount": 999999999999999999999,
"precision": 8
}
},
{
"tokenA": {
"address": "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359",
"minAmount": "1",
"maxAmount": "999999999999999999999",
"precision": 8
},
"tokenX": {
"address": "0x0371a82e4a9d0a4312f3ee2ac9c6958512891372",
"minAmount": "1",
"maxAmount": "999999999999999999999",
"precision": 8
}
}
]

View File

@ -0,0 +1,16 @@
[
{
"tokenA": {
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"minAmount": "1",
"maxAmount": "999999999999999999999",
"precision": 8
},
"tokenB": {
"address": "0xe41d2489571d322189246dafa5ebde1f4699f498",
"minAmount": "1",
"maxAmount": "999999999999999999999",
"precision": 8
}
}
]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,76 @@
import 'mocha';
import * as nock from 'nock';
import * as defaultRequestTokenPairsResponseJSON from './fixtures/v0/token_pairs/default_request.json';
import * as malformedTokenPairsResponseJSON from './fixtures/v0/token_pairs/malformed.json';
import * as tokenAAndTokenBParamsTokenPairsResponseJSON from './fixtures/v0/token_pairs/token_a_and_token_b_params.json';
import * as tokenAParamTokenPairsResponseJSON from './fixtures/v0/token_pairs/token_a_param.json';
import * as tokenBParamTokenPairsResponseJSON from './fixtures/v0/token_pairs/token_b_param.json';
import { testRunner } from './test_runner';
describe('Postman Collection v0', () => {
const testRelayerUrl = 'https://example.com';
const nockScope = nock(testRelayerUrl);
afterEach(() => {
nock.cleanAll();
});
describe('GET /token_pairs', () => {
const postmanCollectionFolderName = 'GET /token_pairs';
const resourcePath = '/token_pairs';
describe('default request', () => {
const postmanCollectionRequestName = 'default request';
const nockInterceptor = nockScope.get(resourcePath);
testRunner.runContentTypeTests(nockInterceptor, postmanCollectionFolderName, postmanCollectionRequestName);
testRunner.runSchemaTests(
nockInterceptor,
postmanCollectionFolderName,
postmanCollectionRequestName,
malformedTokenPairsResponseJSON,
defaultRequestTokenPairsResponseJSON,
);
});
describe('tokenA param', () => {
const postmanCollectionRequestName = 'tokenA param';
const nockInterceptor = nockScope.get(resourcePath).query({
tokenA: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
});
testRunner.runContentTypeTests(nockInterceptor, postmanCollectionFolderName, postmanCollectionRequestName);
testRunner.runSchemaTests(
nockInterceptor,
postmanCollectionFolderName,
postmanCollectionRequestName,
malformedTokenPairsResponseJSON,
tokenAParamTokenPairsResponseJSON,
);
});
describe('tokenB param', () => {
const postmanCollectionRequestName = 'tokenB param';
const nockInterceptor = nockScope.get(resourcePath).query({
tokenB: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
});
testRunner.runContentTypeTests(nockInterceptor, postmanCollectionFolderName, postmanCollectionRequestName);
testRunner.runSchemaTests(
nockInterceptor,
postmanCollectionFolderName,
postmanCollectionRequestName,
malformedTokenPairsResponseJSON,
tokenBParamTokenPairsResponseJSON,
);
});
describe('tokenA and tokenB params', () => {
const postmanCollectionRequestName = 'tokenA and tokenB params';
const nockInterceptor = nockScope.get(resourcePath).query({
tokenA: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
tokenB: '0xe41d2489571d322189246dafa5ebde1f4699f498',
});
testRunner.runContentTypeTests(nockInterceptor, postmanCollectionFolderName, postmanCollectionRequestName);
testRunner.runSchemaTests(
nockInterceptor,
postmanCollectionFolderName,
postmanCollectionRequestName,
malformedTokenPairsResponseJSON,
tokenAAndTokenBParamsTokenPairsResponseJSON,
);
});
});
});

View File

@ -0,0 +1,138 @@
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as dirtyChai from 'dirty-chai';
import * as _ from 'lodash';
import 'mocha';
import { NewmanRunExecution, NewmanRunExecutionAssertion, NewmanRunSummary } from 'newman';
import * as nock from 'nock';
import * as sraReportCollectionJSON from '../../postman_collections/sra_report.postman_collection.json';
import { utils } from '../src/utils';
import * as postmanEnvironmentJSON from './environments/postman_environment.json';
chai.config.includeStack = true;
chai.use(dirtyChai);
chai.use(chaiAsPromised);
const expect = chai.expect;
const CONTENT_TYPE_ASSERTION_NAME = 'Has Content-Type header with value application/json';
const SCHEMA_ASSERTION_NAME = 'Schema is valid';
const baseNewmanRunOptions = {
collection: sraReportCollectionJSON,
environment: postmanEnvironmentJSON,
reporter: {
cli: {
noConsole: true,
},
},
};
export const testRunner = {
runContentTypeTests(
nockInterceptor: nock.Interceptor,
postmanCollectionFolderName: string,
postmanCollectionRequestName: string,
) {
const newmanRunOptions = {
...baseNewmanRunOptions,
folder: postmanCollectionFolderName,
};
describe(CONTENT_TYPE_ASSERTION_NAME, () => {
it('fails when there are no headers', async () => {
nockInterceptor.reply(200, {});
const summary = await utils.newmanRunAsync(newmanRunOptions);
const error = findAssertionErrorIfExists(
summary,
postmanCollectionRequestName,
CONTENT_TYPE_ASSERTION_NAME,
);
const errorMessage = _.get(error, 'message');
expect(error).to.not.be.undefined();
expect(errorMessage).to.equal(`expected response to have header with key 'Content-Type'`);
});
it('fails when Content-Type header exists but not with value application/json', async () => {
const headers = {
'Content-Type': 'text/html',
};
nockInterceptor.reply(200, {}, headers);
const summary = await utils.newmanRunAsync(newmanRunOptions);
const error = findAssertionErrorIfExists(
summary,
postmanCollectionRequestName,
CONTENT_TYPE_ASSERTION_NAME,
);
const errorMessage = _.get(error, 'message');
expect(error).to.not.be.undefined();
expect(errorMessage).to.equal(`expected 'text/html' to include 'application/json'`);
});
it('passes when Content-Type header exists with value application/json', async () => {
const headers = {
'Content-Type': 'charset=utf-8; application/json',
};
nockInterceptor.reply(200, {}, headers);
const summary = await utils.newmanRunAsync(newmanRunOptions);
const error = findAssertionErrorIfExists(
summary,
postmanCollectionRequestName,
CONTENT_TYPE_ASSERTION_NAME,
);
expect(error).to.be.undefined();
});
});
},
runSchemaTests(
nockInterceptor: nock.Interceptor,
postmanCollectionFolderName: string,
postmanCollectionRequestName: string,
malformedJson: object,
correctJson: object,
) {
const newmanRunOptions = {
...baseNewmanRunOptions,
folder: postmanCollectionFolderName,
};
describe(SCHEMA_ASSERTION_NAME, () => {
it('fails when schema is invalid', async () => {
nockInterceptor.reply(200, malformedJson);
const summary = await utils.newmanRunAsync(newmanRunOptions);
const error = findAssertionErrorIfExists(summary, postmanCollectionRequestName, SCHEMA_ASSERTION_NAME);
const errorMessage = _.get(error, 'message');
expect(error).to.not.be.undefined();
expect(errorMessage).to.equal(`expected false to be true`);
});
it('passes when schema is valid', async () => {
nockInterceptor.reply(200, correctJson);
const summary = await utils.newmanRunAsync(newmanRunOptions);
const error = findAssertionErrorIfExists(summary, postmanCollectionRequestName, SCHEMA_ASSERTION_NAME);
const errorMessage = _.get(error, 'message');
expect(error).to.be.undefined();
});
});
},
};
function findAssertionErrorIfExists(
summary: NewmanRunSummary,
postmanCollectionRequestName: string,
postmanCollectionAssertionName: string,
) {
const matchingExecutionIfExists = _.find(summary.run.executions, (execution: NewmanRunExecution) => {
return execution.item.name === postmanCollectionRequestName;
});
if (_.isUndefined(matchingExecutionIfExists)) {
return undefined;
}
const matchingAssertionIfExists = _.find(
matchingExecutionIfExists.assertions,
(assertion: NewmanRunExecutionAssertion) => {
return assertion.assertion === postmanCollectionAssertionName;
},
);
if (_.isUndefined(matchingAssertionIfExists)) {
return undefined;
} else {
const error = matchingAssertionIfExists.error;
return error;
}
}

View File

@ -5,6 +5,9 @@
},
"include": [
"./src/**/*",
"./test/**/*",
"../../node_modules/chai-as-promised-typescript-typings/index.d.ts",
"../../node_modules/chai-typescript-typings/index.d.ts",
"../../node_modules/web3-typescript-typings/index.d.ts",
"../../node_modules/ethers-typescript-typings/index.d.ts"
]

View File

@ -186,12 +186,22 @@
version "2.2.46"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.46.tgz#b04713f7759d1cf752effdaae7b3969e285ebc16"
"@types/mocha@^2.2.48":
version "2.2.48"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.48.tgz#3523b126a0b049482e1c3c11877460f76622ffab"
"@types/moment@^2.13.0":
version "2.13.0"
resolved "https://registry.yarnpkg.com/@types/moment/-/moment-2.13.0.tgz#604ebd189bc3bc34a1548689404e61a2a4aac896"
dependencies:
moment "*"
"@types/nock@^9.1.2":
version "9.1.2"
resolved "https://registry.yarnpkg.com/@types/nock/-/nock-9.1.2.tgz#0515b27e3f6bbc11834d22508ad02e2921dd376a"
dependencies:
"@types/node" "*"
"@types/node@*":
version "9.3.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.3.0.tgz#3a129cda7c4e5df2409702626892cb4b96546dd5"
@ -1754,7 +1764,7 @@ chai-bignumber@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/chai-bignumber/-/chai-bignumber-2.0.2.tgz#de6c219c690b2d66b646ad6930096f9ba2199643"
chai@^4.0.1:
chai@^4.0.1, chai@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.1.2.tgz#0f64584ba642f0f2ace2806279f4f06ca23ad73c"
dependencies:
@ -2401,6 +2411,17 @@ copyfiles@^1.2.0:
noms "0.0.0"
through2 "^2.0.1"
copyfiles@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/copyfiles/-/copyfiles-2.0.0.tgz#bbd78bb78e8fd6db5c67adf54249317b24560f2a"
dependencies:
glob "^7.0.5"
minimatch "^3.0.3"
mkdirp "^0.5.1"
noms "0.0.0"
through2 "^2.0.1"
yargs "^11.0.0"
core-js@^1.0.0:
version "1.2.7"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
@ -2744,7 +2765,7 @@ deep-eql@^3.0.0:
dependencies:
type-detect "^4.0.0"
deep-equal@^1.0.1, deep-equal@~1.0.1:
deep-equal@^1.0.0, deep-equal@^1.0.1, deep-equal@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5"
@ -5822,6 +5843,10 @@ lodash@^3.10.1, lodash@^3.3.1, lodash@^3.6.0:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
lodash@^4.17.5:
version "4.17.5"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"
lodash@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-1.0.2.tgz#8f57560c83b59fc270bd3d561b690043430e2551"
@ -6353,6 +6378,20 @@ nise@^1.2.0:
path-to-regexp "^1.7.0"
text-encoding "^0.6.4"
nock@^9.2.3:
version "9.2.3"
resolved "https://registry.yarnpkg.com/nock/-/nock-9.2.3.tgz#39738087d6a0497d3a165fb352612b38a2f9b92f"
dependencies:
chai "^4.1.2"
debug "^3.1.0"
deep-equal "^1.0.0"
json-stringify-safe "^5.0.1"
lodash "^4.17.5"
mkdirp "^0.5.0"
propagate "^1.0.0"
qs "^6.5.1"
semver "^5.5.0"
node-abi@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-2.3.0.tgz#f3d554d6ac72a9ee16f0f4dc9548db7c08de4986"
@ -7522,6 +7561,10 @@ prop-types@^15.0.0, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6,
loose-envify "^1.3.1"
object-assign "^4.1.1"
propagate@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/propagate/-/propagate-1.0.0.tgz#00c2daeedda20e87e3782b344adba1cddd6ad709"
proxy-addr@~2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.2.tgz#6571504f47bb988ec8180253f85dd7e14952bdec"
@ -7618,7 +7661,7 @@ q@^1.1.2, q@^1.4.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
qs@6.5.1, qs@~6.5.1:
qs@6.5.1, qs@^6.5.1, qs@~6.5.1:
version "6.5.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"
@ -8532,7 +8575,7 @@ semver-sort@0.0.4, semver-sort@^0.0.4:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
semver@5.5.0:
semver@5.5.0, semver@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"
@ -10698,6 +10741,12 @@ yargs-parser@^8.0.0, yargs-parser@^8.1.0:
dependencies:
camelcase "^4.1.0"
yargs-parser@^9.0.2:
version "9.0.2"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-9.0.2.tgz#9ccf6a43460fe4ed40a9bb68f48d43b8a68cc077"
dependencies:
camelcase "^4.1.0"
yargs@6.6.0:
version "6.6.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-6.6.0.tgz#782ec21ef403345f830a808ca3d513af56065208"
@ -10733,6 +10782,23 @@ yargs@^10.0.3:
y18n "^3.2.1"
yargs-parser "^8.1.0"
yargs@^11.0.0:
version "11.0.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-11.0.0.tgz#c052931006c5eee74610e5fc0354bedfd08a201b"
dependencies:
cliui "^4.0.0"
decamelize "^1.1.1"
find-up "^2.1.0"
get-caller-file "^1.0.1"
os-locale "^2.0.0"
require-directory "^2.1.1"
require-main-filename "^1.0.1"
set-blocking "^2.0.0"
string-width "^2.0.0"
which-module "^2.0.0"
y18n "^3.2.1"
yargs-parser "^9.0.2"
yargs@^4.7.1, yargs@~4.8.0:
version "4.8.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-4.8.1.tgz#c0c42924ca4aaa6b0e6da1739dfb216439f9ddc0"