Skip to content

Commit 384a129

Browse files
committed
black box testing, wait with json-mocking support until json-schema-faker fixes some bugs.
1 parent 6ade59b commit 384a129

File tree

7 files changed

+97
-19
lines changed

7 files changed

+97
-19
lines changed

deno.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"compilerOptions": {
33
"checkJs": true
4+
},
5+
"imports": {
6+
"fs": "https://deno.land/[email protected]/node/fs.ts",
7+
"yaml": "https://deno.land/[email protected]/encoding/yaml.ts",
8+
"command": "https://deno.land/x/[email protected]/commander/index.ts"
49
}
5-
}
10+
}

import_map.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

scenario-black-box.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as sync from './src/execute-black-box.js'
22
import * as scenarioAlgorithms from './src/scenario-algorithm.js'
33
import utils from './src/utils.js'
44

5-
import { Command } from 'https://deno.land/x/[email protected]/commander/index.ts'
5+
import {Command} from 'command'
66

77
const program = new Command()
88

@@ -38,10 +38,8 @@ const scenarioJson = scenarioAlgorithms.createScenarios(input)
3838
sync.executeBlackBox(scenarioJson, 0)
3939
.then(data => {
4040
console.log(JSON.stringify(data, null, 2))
41-
return data
4241
})
4342
.catch(e => {
4443
console.log(e)
45-
return e
4644
})
4745

src/json-mock-from-schema.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import toJsonSchema from 'npm:@openapi-contrib/openapi-schema-to-json-schema@latest'
2-
import jsf from 'npm:json-schema-faker@latest'
3-
// After fix use this one: import jsf from 'npm:json-schema-faker@latest/esm'
1+
// import toJsonSchema from 'npm:@openapi-contrib/openapi-schema-to-json-schema@latest'
2+
// import jsf from 'npm:json-schema-faker@latest'
43

5-
jsf.option({
6-
useExamplesValue: true,
7-
random: () => 0.000001
8-
})
4+
// import maps:
5+
// "openapi-schema-to-json-schema": "npm:@openapi-contrib/openapi-schema-to-json-schema@latest",
6+
// "json-schema-faker": "npm:json-schema-faker@latest"
7+
// After fix use this one: import jsf from 'npm:json-schema-faker@latest/esm'
8+
// jsf.option({
9+
// useExamplesValue: true,
10+
// random: () => 0.000001
11+
// })
912

1013
export const SchemaType = {
1114
OPENAPI: 'openapi',
@@ -16,6 +19,11 @@ export function toSchemaType(schema) {
1619
return schema.openapi ? SchemaType.OPENAPI : SchemaType.JSON
1720
}
1821

22+
export function toJsonMock(type, schema) {
23+
return undefined
24+
}
25+
26+
/*
1927
export function toJsonMock(type, schema) {
2028
if (!schema) {
2129
return undefined
@@ -50,3 +58,4 @@ function toJsonMockFromOpenapi(schema) {
5058
function toJsonMockFromJsonSchema(schema) {
5159
return jsf.generate(schema)
5260
}
61+
*/

src/scenario-algorithm.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ function toTechnology(technology) {
77
}
88

99
function replaceData(target, config) {
10+
if(target === undefined) {
11+
return {}
12+
}
13+
1014
let returnTarget = target
1115
Object.keys(config)
1216
.forEach(key => {
@@ -91,7 +95,7 @@ function toInteraction(input) {
9195

9296
Object.keys(input.requestTemplate)
9397
.forEach(key => {
94-
if (input.generateAlways) {
98+
if (input.generateAlways && input.generateAlways.length > 0) {
9599
interaction.request[key] = replaceAlways(JSON.stringify(input.requestTemplate[key]), input.replace, input.generateAlways)
96100
}
97101
else {
@@ -101,7 +105,7 @@ function toInteraction(input) {
101105

102106
Object.keys(input.responseTemplate)
103107
.forEach(key => {
104-
if (input.generateAlways) {
108+
if (input.generateAlways && input.generateAlways.length > 0) {
105109
interaction.response[key] = replaceAlways(JSON.stringify(input.responseTemplate[key]), input.replace, input.generateAlways)
106110
}
107111
else {

src/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {readFileSync} from 'https://deno.land/[email protected]/node/fs.ts'
2-
import {parse} from "https://deno.land/[email protected]/encoding/yaml.ts";
1+
import {readFileSync} from 'fs'
2+
import {parse} from 'yaml'
33

44
function randomIban(countryCode, technicalOrgNum) {
55
return countryCode + randomInteger(20, 90) + technicalOrgNum + randomInteger(1000000, 9999999)
@@ -129,7 +129,7 @@ export default {
129129
openFile: fileName => {
130130
const text = readFileSync(toPath(fileName)).toString()
131131

132-
if(fileName.endsWith(".yaml") || fileName.endsWith(".yml")) {
132+
if (fileName.endsWith('.yaml') || fileName.endsWith('.yml')) {
133133
return parse(text)
134134
}
135135
return JSON.parse(text)

test-data/perform-eod.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"headerTemplateFile": "./templates/led-server-http-header-template.json",
3+
"replace": {
4+
"url": "https://eos-led-server-d5.apps.os-global.finods.com/led/api/v1",
5+
"reportUrl": "https://eos-led-reports--d5.apps.os-global.finods.com",
6+
"bankOrgID": "3060",
7+
"iban": "NO4430606107869"
8+
},
9+
"interactions": {
10+
"systemDate": {
11+
"request": {
12+
"path": "{url}/test/systemdate/next/{bankOrgID}",
13+
"method": "POST",
14+
"output": "systemDate"
15+
}
16+
},
17+
"eodOnAccount": {
18+
"request": {
19+
"path": "{url}/eod/accounts",
20+
"method": "POST",
21+
"body": {
22+
"ibans": [
23+
"{iban}"
24+
]
25+
}
26+
}
27+
},
28+
"findLedEodReport": {
29+
"request": {
30+
"input": [
31+
"systemDate"
32+
],
33+
"path": "{reportUrl}/find/D5/LED-EOD/{bankOrgID}/{systemDate.body.{bankOrgID}}",
34+
"output": "findLedEodReport"
35+
}
36+
},
37+
"findLedEodRsbReport": {
38+
"request": {
39+
"input": [
40+
"systemDate"
41+
],
42+
"path": "{reportUrl}/find/D5/LED-EOD-RSB/{bankOrgID}/{systemDate.body.{bankOrgID}}",
43+
"output": "findLedEodRsbReport"
44+
}
45+
},
46+
"readLedEodReport": {
47+
"request": {
48+
"input": [
49+
"systemDate",
50+
"findLedEodReport"
51+
],
52+
"path": "{reportUrl}{findLedEodReport.body.urls.0}"
53+
}
54+
},
55+
"readLedEodRsbReport": {
56+
"request": {
57+
"input": [
58+
"systemDate",
59+
"findLedEodRsbReport"
60+
],
61+
"path": "{reportUrl}{findLedEodRsbReport.body.urls.0}"
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)