feat(#1296): restructured toml json test setup

This commit is contained in:
Anoop M D 2023-12-30 17:13:15 +05:30
parent 41d0698a87
commit 35b6f7bb0a
7 changed files with 92 additions and 8 deletions

View File

@ -0,0 +1,18 @@
const fs = require('fs');
const path = require('path');
const jsonToToml = require('../src/jsonToToml');
const { describe } = require('@jest/globals');
const fixtures = ['methods/get', 'methods/delete'];
describe('bruno toml', () => {
fixtures.forEach((fixture) => {
describe(fixture, () => {
const json = require(`./${fixture}/request.json`);
const toml = fs.readFileSync(path.join(__dirname, fixture, 'request.toml'), 'utf8');
it(`should convert json to toml`, () => {
expect(toml).toEqual(jsonToToml(json));
});
});
});
});

View File

@ -0,0 +1,35 @@
const jsonToToml = require('../../src/jsonToToml');
const json = {
meta: {
name: 'Get users',
type: 'http',
seq: '1'
},
http: {
method: 'get',
url: 'https://reqres.in/api/users'
},
headers: {
Accept: 'application/json'
}
};
const toml = `[meta]
name = 'Get users'
type = 'http'
seq = '1'
[http]
method = 'get'
url = 'https://reqres.in/api/users'
[headers]
Accept = 'application/json'
`;
describe('jsonToToml - simple get', () => {
it('should parse the json file', () => {
expect(jsonToToml(json)).toEqual(toml);
});
});

View File

@ -1,4 +1,3 @@
const TOML = require('@iarna/toml');
const jsonToToml = require('../../src/jsonToToml'); const jsonToToml = require('../../src/jsonToToml');
const json = { const json = {
@ -10,9 +9,6 @@ const json = {
http: { http: {
method: 'get', method: 'get',
url: 'https://reqres.in/api/users' url: 'https://reqres.in/api/users'
},
headers: {
Accept: 'application/json'
} }
}; };
@ -24,13 +20,10 @@ seq = '1'
[http] [http]
method = 'get' method = 'get'
url = 'https://reqres.in/api/users' url = 'https://reqres.in/api/users'
[headers]
Accept = 'application/json'
`; `;
describe('jsonToToml - simple get', () => { describe('jsonToToml - simple get', () => {
it('should parse the json file', () => { it('should parse the json', () => {
expect(jsonToToml(json)).toEqual(toml); expect(jsonToToml(json)).toEqual(toml);
}); });
}); });

View File

@ -0,0 +1,11 @@
{
"meta": {
"name": "Delete User",
"type": "http",
"seq": 1
},
"http": {
"method": "DELETE",
"url": "https://reqres.in/api/users/2"
}
}

View File

@ -0,0 +1,8 @@
[meta]
name = 'Delete User'
type = 'http'
seq = 1
[http]
method = 'DELETE'
url = 'https://reqres.in/api/users/2'

View File

@ -0,0 +1,11 @@
{
"meta": {
"name": "Get users",
"type": "http",
"seq": 1
},
"http": {
"method": "GET",
"url": "https://reqres.in/api/users"
}
}

View File

@ -0,0 +1,8 @@
[meta]
name = 'Get users'
type = 'http'
seq = 1
[http]
method = 'GET'
url = 'https://reqres.in/api/users'