@elasticpath/component-test-framework 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,12 +4,12 @@
4
4
 
5
5
  *With Yarn*
6
6
  ```shell
7
- yarn add --dev @moltin/component-test-framework
7
+ yarn add --dev @elasticpath/component-test-framework
8
8
  ```
9
9
 
10
10
  *With NPM*
11
11
  ```shell
12
- npm install --save-dev @moltin/component-test-framework
12
+ npm install --save-dev @elasticpath/component-test-framework
13
13
  ```
14
14
 
15
15
  ### Usage
@@ -1 +1 @@
1
- {"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAcrC,MAAa,QAAQ;IAGnB,YAAY,IAAY,EAAE,UAAe;QACvC,IAAI,CAAC,IAAI,mBACP,IAAI,IACD,UAAU,CACd,CAAA;QACD,iDAAiD;QACjD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,gFAAgF;IAChF,gFAAgF;IACzE,SAAS,CAAC,gBAA6B;;QACrC,MAAA,IAAI,CAAC,IAAI,+CAAE,IAAI,CAAA;QACf,MAAA,IAAI,CAAC,IAAI,+CAAE,aAAa,CAAA;QAE/B,IAAI,CAAC,gBAAgB,EAAE;YACrB,OAAO,IAAI,CAAC,IAAI,CAAA;SACjB;QAED,MAAM,YAAY,GAAG,gBAAgB,CAAA;QAErC,yDAAyD;QACzD,gCAAgC;QAChC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC5C,YAAY,CAAC,GAAG,CAAC,GAAG,IAAA,mBAAW,EAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAA;QACxD,CAAC,CAAC,CAAA;QAEF,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAA;QAEvB,gEAAgE;QAChE,gCAAgC;QAChC,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE;YAC5D,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,YAAY,CAAC,EAAE,CAAA;YAC9B,OAAO,YAAY,CAAC,EAAE,CAAA,CAAC,uCAAuC;SAC/D;QAED,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE;YAC9D,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAA;YACtC,OAAO,YAAY,CAAC,IAAI,CAAA,CAAC,uCAAuC;SACjE;QAED,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE;YACjE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,CAAA;SACrE;aAAM;YACL,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;SAC/C;QAED,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;CACF;AApDD,4BAoDC","sourcesContent":["import { nullOrValue } from './utils'\n\ninterface Attributes {\n [key: string]: any\n}\n\nexport interface ResourceData {\n id: string\n type: string\n attributes?: Attributes\n // Allow for V2 resources\n [key: string]: any\n}\n\nexport class Resource {\n public data: ResourceData\n\n constructor(type: string, attributes: any) {\n this.data = {\n type,\n ...attributes,\n }\n // eslint-disable-next-line no-constructor-return\n return this\n }\n\n // Returns the resource as a payload, removing all attributes that cannot appear\n // in a payload, as well as converting values from string \"null\" to literal null\n public asPayload(updateAttributes?: Attributes) {\n delete this.data?.meta\n delete this.data?.relationships\n\n if (!updateAttributes) {\n return this.data\n }\n\n const clonedUpdate = updateAttributes\n\n // Loop through all update attributes and nullify the key\n // if its value is string \"null\"\n Object.keys(updateAttributes).forEach((key) => {\n clonedUpdate[key] = nullOrValue(updateAttributes[key])\n })\n\n const clone = this.data\n\n // For those test cases where you want to remove or change these\n // attributes to assert an error\n if (Object.prototype.hasOwnProperty.call(clonedUpdate, 'id')) {\n this.data.id = clonedUpdate.id\n delete clonedUpdate.id // so we don't put it in the attributes\n }\n\n if (Object.prototype.hasOwnProperty.call(clonedUpdate, 'type')) {\n this.data.type = updateAttributes.type\n delete clonedUpdate.type // so we don't put it in the attributes\n }\n\n if (Object.prototype.hasOwnProperty.call(this.data, 'attributes')) {\n this.data.attributes = Object.assign(clone.attributes, clonedUpdate)\n } else {\n this.data = Object.assign(clone, clonedUpdate)\n }\n\n return this.data\n }\n}\n"]}
1
+ {"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAcrC,MAAa,QAAQ;IAGnB,YAAY,IAAY,EAAE,UAAe;QACvC,IAAI,CAAC,IAAI,mBACP,IAAI,IACD,UAAU,CACd,CAAA;QACD,iDAAiD;QACjD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,gFAAgF;IAChF,gFAAgF;IACzE,SAAS,CAAC,gBAA6B;;QACrC,MAAA,IAAI,CAAC,IAAI,+CAAE,IAAI,CAAA;QACf,MAAA,IAAI,CAAC,IAAI,+CAAE,aAAa,CAAA;QAE/B,IAAI,CAAC,gBAAgB,EAAE;YACrB,OAAO,IAAI,CAAC,IAAI,CAAA;SACjB;QAED,MAAM,YAAY,GAAG,gBAAgB,CAAA;QAErC,yDAAyD;QACzD,gCAAgC;QAChC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC5C,YAAY,CAAC,GAAG,CAAC,GAAG,IAAA,mBAAW,EAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAA;QACxD,CAAC,CAAC,CAAA;QAEF,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAA;QAEvB,gEAAgE;QAChE,gCAAgC;QAChC,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE;YAC5D,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,YAAY,CAAC,EAAE,CAAA;YAC9B,OAAO,YAAY,CAAC,EAAE,CAAA,CAAC,uCAAuC;SAC/D;QAED,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE;YAC9D,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAA;YACtC,OAAO,YAAY,CAAC,IAAI,CAAA,CAAC,uCAAuC;SACjE;QAED,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE;YACjE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,CAAA;SACrE;aAAM;YACL,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;SAC/C;QAED,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;CACF;AApDD,4BAoDC","sourcesContent":["import { nullOrValue } from './utils'\n\ninterface Attributes {\n [key: string]: any\n}\n\nexport interface ResourceData {\n id: string\n type: string\n attributes?: Attributes\n // Allow for resources that don't conform to JSONAPI\n [key: string]: any\n}\n\nexport class Resource {\n public data: ResourceData\n\n constructor(type: string, attributes: any) {\n this.data = {\n type,\n ...attributes,\n }\n // eslint-disable-next-line no-constructor-return\n return this\n }\n\n // Returns the resource as a payload, removing all attributes that cannot appear\n // in a payload, as well as converting values from string \"null\" to literal null\n public asPayload(updateAttributes?: Attributes) {\n delete this.data?.meta\n delete this.data?.relationships\n\n if (!updateAttributes) {\n return this.data\n }\n\n const clonedUpdate = updateAttributes\n\n // Loop through all update attributes and nullify the key\n // if its value is string \"null\"\n Object.keys(updateAttributes).forEach((key) => {\n clonedUpdate[key] = nullOrValue(updateAttributes[key])\n })\n\n const clone = this.data\n\n // For those test cases where you want to remove or change these\n // attributes to assert an error\n if (Object.prototype.hasOwnProperty.call(clonedUpdate, 'id')) {\n this.data.id = clonedUpdate.id\n delete clonedUpdate.id // so we don't put it in the attributes\n }\n\n if (Object.prototype.hasOwnProperty.call(clonedUpdate, 'type')) {\n this.data.type = updateAttributes.type\n delete clonedUpdate.type // so we don't put it in the attributes\n }\n\n if (Object.prototype.hasOwnProperty.call(this.data, 'attributes')) {\n this.data.attributes = Object.assign(clone.attributes, clonedUpdate)\n } else {\n this.data = Object.assign(clone, clonedUpdate)\n }\n\n return this.data\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { ApiResponse, ApiArrayResponse } from './api.interfaces';
2
- import { ResourceData, Resource } from './resource';
2
+ import { Resource } from './resource';
3
3
  export default class ResourceStore {
4
4
  private static resources;
5
- static FetchByType(type: string): ResourceData;
5
+ static FetchByType(type: string): Resource;
6
6
  /**
7
7
  * Finds the resource by looking for the key and value
8
8
  * @param type {string} the type of resource
@@ -11,7 +11,7 @@ export default class ResourceStore {
11
11
  * @return {Resource | undefined}
12
12
  */
13
13
  static Find(type: string, key: string, value: any): Resource;
14
- static LastCreated(type: string): ResourceData;
14
+ static LastCreated(type: string): Resource;
15
15
  private static isArrayResponse;
16
16
  static Store(responses: ApiResponse | ApiArrayResponse): void;
17
17
  static Clear(): void;
@@ -16,12 +16,12 @@ class ResourceStore {
16
16
  static Find(type, key, value) {
17
17
  const resources = this.resources[type] || [];
18
18
  return resources.find((resource) => {
19
- let target = resource;
19
+ let target = resource.data;
20
20
  if (key.indexOf('.') > -1) {
21
21
  target = key.split('.').reduce((original, i) => original === null || original === void 0 ? void 0 : original[i], target);
22
22
  }
23
23
  else {
24
- target = resource[key];
24
+ target = resource.data[key];
25
25
  }
26
26
  return target === value;
27
27
  });
@@ -48,12 +48,12 @@ class ResourceStore {
48
48
  ;
49
49
  responses.data.forEach((data) => {
50
50
  const resource = new resource_1.Resource(type, data);
51
- this.resources[type].push(resource.data);
51
+ this.resources[type].push(resource);
52
52
  });
53
53
  }
54
54
  else {
55
55
  const resource = new resource_1.Resource(type, responses.data);
56
- this.resources[type].push(resource.data);
56
+ this.resources[type].push(resource);
57
57
  }
58
58
  }
59
59
  static Clear() {
@@ -1 +1 @@
1
- {"version":3,"file":"resource_store.js","sourceRoot":"","sources":["../src/resource_store.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAG7B,yCAAmD;AAEnD,MAAqB,aAAa;IAIzB,MAAM,CAAC,WAAW,CAAC,IAAY;QACpC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,IAAI,CAAC,IAAY,EAAE,GAAW,EAAE,KAAU;QACtD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;QAE5C,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjC,IAAI,MAAM,GAAG,QAAQ,CAAA;YACrB,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;gBACzB,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;aACvE;iBAAM;gBACL,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;aACvB;YAED,OAAO,MAAM,KAAK,KAAK,CAAA;QACzB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAC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uCAAuC;IAC/B,MAAM,CAAC,eAAe,CAAC,SAAyC;;QACtE,IAAI,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;YACnC,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;gBACnC,aAAM,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAA;aAC5D;YACD,OAAO,MAAA,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,IAAI,CAAA;SAC/B;QAED,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,EAAE;YAChC,aAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAA;SACpD;QACD,OAAQ,SAAyB,CAAC,IAAI,CAAC,IAAI,CAAA;IAC7C,CAAC;;AA/ED,sFAAsF;AACvE,uBAAS,GAAwB,EAAE,CAAA;kBAF/B,aAAa","sourcesContent":["import { expect } from 'chai'\n\nimport { ApiResponse, ApiArrayResponse, V3Response, V2Response } from './api.interfaces'\nimport { ResourceData, Resource } from './resource'\n\nexport default class ResourceStore {\n // Contains a list of resources (singular keys for the resource type eg: flow/product)\n private static resources: Array<ResourceData> = []\n\n public static FetchByType(type: string): ResourceData {\n return this.resources[type]\n }\n\n /**\n * Finds the resource by looking for the key and value\n * @param type {string} the type of resource\n * @param key {string} a JSON path string. Eg: attributes.name\n * @param value {any} the value to look for\n * @return {Resource | undefined}\n */\n public static Find(type: string, key: string, value: any): Resource {\n const resources = this.resources[type] || []\n\n return resources.find((resource) => {\n let target = resource\n if (key.indexOf('.') > -1) {\n target = key.split('.').reduce((original, i) => original?.[i], target)\n } else {\n target = resource[key]\n }\n\n return target === value\n })\n }\n\n /*\n Returns the last created resource\n @param type string The type of the resource, eg: product\n @return The Resource\n */\n public static LastCreated(type: string): ResourceData {\n const resources = this.resources[type] || []\n return resources[resources.length - 1]\n }\n\n private static isArrayResponse(responses: ApiResponse | ApiArrayResponse): boolean {\n return (responses as ApiArrayResponse)?.data?.length !== undefined\n }\n\n public static Store(responses: ApiResponse | ApiArrayResponse): void {\n const type = this.getResourceType(responses)\n\n if (!Object.prototype.hasOwnProperty.call(this.resources, type)) {\n this.resources[type] = []\n }\n\n if (this.isArrayResponse(responses)) {\n ;(responses.data as Array<V3Response | V2Response>).forEach((data) => {\n const resource = new Resource(type, data)\n this.resources[type].push(resource.data)\n })\n } else {\n const resource = new Resource(type, responses.data)\n this.resources[type].push(resource.data)\n }\n }\n\n public static Clear(): void {\n this.resources = []\n }\n\n // Gets the type of the resource, taking in to account an array API response, where it will\n // infer the type from the first object\n private static getResourceType(responses: ApiResponse | ApiArrayResponse): string {\n if (this.isArrayResponse(responses)) {\n if (responses.data[0] === undefined) {\n expect.fail('Could not find any resources in the response')\n }\n return responses.data[0]?.type\n }\n\n if (responses.data === undefined) {\n expect.fail('Could not a resource in the response')\n }\n return (responses as ApiResponse).data.type\n }\n}\n"]}
1
+ {"version":3,"file":"resource_store.js","sourceRoot":"","sources":["../src/resource_store.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAG7B,yCAAqC;AAErC,MAAqB,aAAa;IAIzB,MAAM,CAAC,WAAW,CAAC,IAAY;QACpC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,IAAI,CAAC,IAAY,EAAE,GAAW,EAAE,KAAU;QACtD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;QAE5C,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjC,IAAI,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAA;YAC1B,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;gBACzB,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,QA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,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;YACnD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SACpC;IACH,CAAC;IAEM,MAAM,CAAC,KAAK;QACjB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAA;IACrB,CAAC;IAED,2FAA2F;IAC3F,uCAAuC;IAC/B,MAAM,CAAC,eAAe,CAAC,SAAyC;;QACtE,IAAI,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;YACnC,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;gBACnC,aAAM,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAA;aAC5D;YACD,OAAO,MAAA,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,IAAI,CAAA;SAC/B;QAED,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,EAAE;YAChC,aAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAA;SACpD;QACD,OAAQ,SAAyB,CAAC,IAAI,CAAC,IAAI,CAAA;IAC7C,CAAC;;AA/ED,sFAAsF;AACvE,uBAAS,GAAoB,EAAE,CAAA;kBAF3B,aAAa","sourcesContent":["import { expect } from 'chai'\n\nimport { ApiResponse, ApiArrayResponse, V3Response, V2Response } from './api.interfaces'\nimport { Resource } from './resource'\n\nexport default class ResourceStore {\n // Contains a list of resources (singular keys for the resource type eg: flow/product)\n private static resources: Array<Resource> = []\n\n public static FetchByType(type: string): Resource {\n return this.resources[type]\n }\n\n /**\n * Finds the resource by looking for the key and value\n * @param type {string} the type of resource\n * @param key {string} a JSON path string. Eg: attributes.name\n * @param value {any} the value to look for\n * @return {Resource | undefined}\n */\n public static Find(type: string, key: string, value: any): Resource {\n const resources = this.resources[type] || []\n\n return resources.find((resource) => {\n let target = resource.data\n if (key.indexOf('.') > -1) {\n target = key.split('.').reduce((original, i) => original?.[i], target)\n } else {\n target = resource.data[key]\n }\n\n return target === value\n })\n }\n\n /*\n Returns the last created resource\n @param type string The type of the resource, eg: product\n @return The Resource\n */\n public static LastCreated(type: string): Resource {\n const resources = this.resources[type] || []\n return resources[resources.length - 1]\n }\n\n private static isArrayResponse(responses: ApiResponse | ApiArrayResponse): boolean {\n return (responses as ApiArrayResponse)?.data?.length !== undefined\n }\n\n public static Store(responses: ApiResponse | ApiArrayResponse): void {\n const type = this.getResourceType(responses)\n\n if (!Object.prototype.hasOwnProperty.call(this.resources, type)) {\n this.resources[type] = []\n }\n\n if (this.isArrayResponse(responses)) {\n ;(responses.data as Array<V3Response | V2Response>).forEach((data) => {\n const resource = new Resource(type, data)\n this.resources[type].push(resource)\n })\n } else {\n const resource = new Resource(type, responses.data)\n this.resources[type].push(resource)\n }\n }\n\n public static Clear(): void {\n this.resources = []\n }\n\n // Gets the type of the resource, taking in to account an array API response, where it will\n // infer the type from the first object\n private static getResourceType(responses: ApiResponse | ApiArrayResponse): string {\n if (this.isArrayResponse(responses)) {\n if (responses.data[0] === undefined) {\n expect.fail('Could not find any resources in the response')\n }\n return responses.data[0]?.type\n }\n\n if (responses.data === undefined) {\n expect.fail('Could not a resource in the response')\n }\n return (responses as ApiResponse).data.type\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elasticpath/component-test-framework",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "A framework for component tests written using ts-flow",
5
5
  "main": "./lib/index.js",
6
6
  "directories": {