diff --git a/packages/bruno-toml/tests/index.spec.js b/packages/bruno-toml/tests/index.spec.js new file mode 100644 index 00000000..10952e82 --- /dev/null +++ b/packages/bruno-toml/tests/index.spec.js @@ -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)); + }); + }); + }); +}); diff --git a/packages/bruno-toml/tests/jsonToToml/headers/headers-simple.spec.js b/packages/bruno-toml/tests/jsonToToml/headers/headers-simple.spec.js new file mode 100644 index 00000000..d8085477 --- /dev/null +++ b/packages/bruno-toml/tests/jsonToToml/headers/headers-simple.spec.js @@ -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); + }); +}); diff --git a/packages/bruno-toml/tests/jsonToToml/simple-get.spec.js b/packages/bruno-toml/tests/jsonToToml/simple-get.spec.js index b4817bc7..814bda81 100644 --- a/packages/bruno-toml/tests/jsonToToml/simple-get.spec.js +++ b/packages/bruno-toml/tests/jsonToToml/simple-get.spec.js @@ -1,4 +1,3 @@ -const TOML = require('@iarna/toml'); const jsonToToml = require('../../src/jsonToToml'); const json = { @@ -10,9 +9,6 @@ const json = { http: { method: 'get', url: 'https://reqres.in/api/users' - }, - headers: { - Accept: 'application/json' } }; @@ -24,13 +20,10 @@ 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', () => { + it('should parse the json', () => { expect(jsonToToml(json)).toEqual(toml); }); }); diff --git a/packages/bruno-toml/tests/methods/delete/request.json b/packages/bruno-toml/tests/methods/delete/request.json new file mode 100644 index 00000000..8ed28e87 --- /dev/null +++ b/packages/bruno-toml/tests/methods/delete/request.json @@ -0,0 +1,11 @@ +{ + "meta": { + "name": "Delete User", + "type": "http", + "seq": 1 + }, + "http": { + "method": "DELETE", + "url": "https://reqres.in/api/users/2" + } +} diff --git a/packages/bruno-toml/tests/methods/delete/request.toml b/packages/bruno-toml/tests/methods/delete/request.toml new file mode 100644 index 00000000..0a7673f6 --- /dev/null +++ b/packages/bruno-toml/tests/methods/delete/request.toml @@ -0,0 +1,8 @@ +[meta] +name = 'Delete User' +type = 'http' +seq = 1 + +[http] +method = 'DELETE' +url = 'https://reqres.in/api/users/2' diff --git a/packages/bruno-toml/tests/methods/get/request.json b/packages/bruno-toml/tests/methods/get/request.json new file mode 100644 index 00000000..2fb3955f --- /dev/null +++ b/packages/bruno-toml/tests/methods/get/request.json @@ -0,0 +1,11 @@ +{ + "meta": { + "name": "Get users", + "type": "http", + "seq": 1 + }, + "http": { + "method": "GET", + "url": "https://reqres.in/api/users" + } +} diff --git a/packages/bruno-toml/tests/methods/get/request.toml b/packages/bruno-toml/tests/methods/get/request.toml new file mode 100644 index 00000000..ae34e077 --- /dev/null +++ b/packages/bruno-toml/tests/methods/get/request.toml @@ -0,0 +1,8 @@ +[meta] +name = 'Get users' +type = 'http' +seq = 1 + +[http] +method = 'GET' +url = 'https://reqres.in/api/users'