(json)
| 14 | }; |
| 15 | |
| 16 | const jsonToBru = (json) => { |
| 17 | const { meta, http, grpc, ws, params, headers, metadata, auth, body, script, tests, vars, assertions, settings, docs, examples } = json; |
| 18 | |
| 19 | let bru = ''; |
| 20 | |
| 21 | if (meta) { |
| 22 | bru += 'meta {\n'; |
| 23 | |
| 24 | const tags = meta.tags; |
| 25 | delete meta.tags; |
| 26 | |
| 27 | for (const key in meta) { |
| 28 | bru += ` ${key}: ${meta[key]}\n`; |
| 29 | } |
| 30 | |
| 31 | if (tags && tags.length) { |
| 32 | bru += ` tags: [\n`; |
| 33 | for (const tag of tags) { |
| 34 | bru += ` ${tag}\n`; |
| 35 | } |
| 36 | bru += ` ]\n`; |
| 37 | } |
| 38 | |
| 39 | bru += '}\n\n'; |
| 40 | } |
| 41 | |
| 42 | if (http?.method) { |
| 43 | const { method, url, body, auth } = http; |
| 44 | const standardMethods = new Set(['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace', 'connect']); |
| 45 | |
| 46 | const isStandard = standardMethods.has(method); |
| 47 | |
| 48 | bru += isStandard ? `${method} {` : `http {\n method: ${method}`; |
| 49 | bru += `\n url: ${getValueUrl(url)}`; |
| 50 | |
| 51 | if (body?.length) { |
| 52 | bru += `\n body: ${body}`; |
| 53 | } |
| 54 | |
| 55 | if (auth?.length) { |
| 56 | bru += `\n auth: ${auth}`; |
| 57 | } |
| 58 | |
| 59 | bru += `\n}\n\n`; |
| 60 | } |
| 61 | |
| 62 | if (grpc && grpc.url) { |
| 63 | bru += `grpc { |
| 64 | url: ${grpc.url}`; |
| 65 | |
| 66 | if (grpc.method && grpc.method.length) { |
| 67 | bru += ` |
| 68 | method: ${grpc.method}`; |
| 69 | } |
| 70 | |
| 71 | if (grpc.body && grpc.body.length) { |
| 72 | bru += ` |
| 73 | body: ${grpc.body}`; |
no test coverage detected