@skyramp/skyramp 0.4.39 → 0.4.41

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.
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyramp/skyramp",
3
- "version": "0.4.39",
3
+ "version": "0.4.41",
4
4
  "description": "module for leveraging skyramp cli functionality",
5
5
  "scripts": {
6
6
  "pack": "npm pack"
@@ -1,5 +1,5 @@
1
1
  const lib = require('../lib');
2
- const { getYamlBytes, readDataFromFile } = require('../utils');
2
+ const { getYamlBytes, readDataFromFile, SKYRAMP_YAML_VERSION } = require('../utils');
3
3
  const writeMockDescriptionWrapper = lib.func('writeMockDescriptionWrapper', 'string', ['string', 'string']);
4
4
 
5
5
  class Endpoint {
@@ -8,14 +8,14 @@ class Endpoint {
8
8
  const endpoint = JSON.parse(endpointData);
9
9
  this.services = endpoint.services;
10
10
  this.endpoint = endpoint.endpoints[0];
11
- for (const method of this.endpoint.methods) {
12
- method.proxy = true;
13
- }
14
- this.responseValues = endpoint.responseValues;
11
+
12
+ this.responses = endpoint.responses;
13
+
15
14
  this.mockDescription = {
15
+ version: SKYRAMP_YAML_VERSION,
16
16
  services: this.services,
17
17
  endpoints: [this.endpoint],
18
- responseValues: this.responseValues
18
+ responses: this.responses
19
19
  };
20
20
  } catch(error) {
21
21
  throw new Error(endpointData);
@@ -23,25 +23,36 @@ class Endpoint {
23
23
  }
24
24
 
25
25
  mockMethod(methodName, mockObject, dynamic=false) {
26
- for (const method of this.endpoint.methods) {
27
- if (method.name === methodName || method.type === methodName) {
28
- const responseName = method.responseValue;
29
- delete method.proxy;
30
- for (const responseValue of this.responseValues) {
31
- if (responseValue.name === responseName) {
32
- if (dynamic) {
33
- responseValue.javascriptPath = mockObject;
34
- delete responseValue.blob;
35
- } else {
36
- responseValue.blob = mockObject.responseValue.blob;
37
- delete responseValue.javascriptPath;
38
- }
39
- return;
40
- }
26
+ if (!this.endpoint.methods.some(method => method.name === methodName)) {
27
+ throw new Error(`Method ${methodName} not found`);
28
+ }
29
+
30
+ for (const response of this.responses) {
31
+ if (response.methodName === methodName && response.endpointName === this.endpoint.name) {
32
+ if (dynamic) {
33
+ response.javascriptPath = mockObject;
34
+ delete response.blob;
35
+ } else {
36
+ response.blob = mockObject.responseValue.blob;
37
+ delete response.javascriptPath;
41
38
  }
39
+
40
+ return;
42
41
  }
43
42
  }
44
- throw new Error(`Method ${methodName} not found`);
43
+
44
+ newResponse = {
45
+ methodName: methodName,
46
+ endpointName: this.endpoint.name
47
+ };
48
+
49
+ if (dynamic) {
50
+ newResponse.javascriptPath = mock;
51
+ } else {
52
+ newResponse.blob = mockObject.responseValue.blob;
53
+ }
54
+
55
+ this.responses.append(newResponse)
45
56
  }
46
57
 
47
58
  mockMethodFromFile(methodName, fileName) {
@@ -15,14 +15,14 @@ class Scenario {
15
15
  addRequest(endpoint, methodName, requestObject=undefined, dynamic=false) {
16
16
  this.buildRequestsFromEndpoint(endpoint);
17
17
  for (const request of this.requests) {
18
- if (request.method === methodName) {
18
+ if (request.methodName === methodName) {
19
19
  if (dynamic) {
20
- request.requestValue.javascriptPath = requestObject;
21
- delete request.requestValue.blob;
20
+ request.javascriptPath = requestObject;
21
+ delete request.blob;
22
22
  } else if (requestObject !== undefined) {
23
- request.requestValue = requestObject.requestValue;
23
+ request.blob = requestObject.requestValue.blob;
24
24
  }
25
- this.steps.push({ request: request.name });
25
+ this.steps.push({ requestName: request.name });
26
26
  return request.name;
27
27
  }
28
28
  }
@@ -38,12 +38,10 @@ class Scenario {
38
38
  if (this.endpoints.indexOf(endpoint.endpoint) !== -1) {
39
39
  return;
40
40
  }
41
- const processedMethods = endpoint.endpoint.methods.map(method => {
42
- const { responseValue, proxy, ...rest } = method;
43
- return rest;
44
- });
41
+
45
42
  this.services.push(...endpoint.services);
46
- this.endpoints.push({ ...endpoint.endpoint, methods: processedMethods });
43
+ this.endpoints.push(endpoint.endpoint);
44
+
47
45
  const yamlContent = getYamlBytes(endpoint.mockDescription);
48
46
  const response = buildRequestsWrapper(yamlContent);
49
47
  try {
package/src/utils.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const yaml = require('js-yaml');
4
+ const SKYRAMP_YAML_VERSION = "v1"
4
5
 
5
6
  function getYamlBytes(jsonObject) {
6
7
  try {
@@ -13,11 +14,11 @@ function getYamlBytes(jsonObject) {
13
14
 
14
15
  function createTestDescriptionFromScenario(scenario) {
15
16
  return {
17
+ version: SKYRAMP_YAML_VERSION,
16
18
  test: {
17
- name: scenario.name,
18
19
  testPattern: [{
19
20
  startAt: 1,
20
- scenario: scenario.name
21
+ scenarioName: scenario.name
21
22
  }]
22
23
  },
23
24
  services: scenario.services,
@@ -54,5 +55,6 @@ function readDataFromFile(filename) {
54
55
  module.exports = {
55
56
  createTestDescriptionFromScenario,
56
57
  getYamlBytes,
57
- readDataFromFile
58
+ readDataFromFile,
59
+ SKYRAMP_YAML_VERSION
58
60
  }