bruno/packages/bruno-lang/v2/tests/jsonToEnv.spec.js

144 lines
2.6 KiB
JavaScript
Raw Normal View History

const parser = require('../src/jsonToEnv');
2023-02-05 14:36:48 +01:00
describe('env parser', () => {
it('should parse empty vars', () => {
2023-02-05 14:36:48 +01:00
const input = {
variables: []
2023-02-05 14:36:48 +01:00
};
const output = parser(input);
const expected = `vars {
}
`;
expect(output).toEqual(expected);
});
it('should parse single var line', () => {
2023-02-05 14:36:48 +01:00
const input = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true
}
]
2023-02-05 14:36:48 +01:00
};
const output = parser(input);
const expected = `vars {
url: http://localhost:3000
}
`;
expect(output).toEqual(expected);
});
it('should parse multiple var lines', () => {
2023-02-05 14:36:48 +01:00
const input = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true
},
{
name: 'port',
value: '3000',
enabled: false
}
]
2023-02-05 14:36:48 +01:00
};
const expected = `vars {
url: http://localhost:3000
~port: 3000
}
`;
const output = parser(input);
expect(output).toEqual(expected);
});
it('should parse secret vars', () => {
const input = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true
},
{
name: 'token',
value: 'abracadabra',
enabled: true,
secret: true
}
]
};
const output = parser(input);
const expected = `vars {
url: http://localhost:3000
}
vars:secret [
token
]
`;
expect(output).toEqual(expected);
});
it('should parse multiple secret vars', () => {
const input = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true
},
{
name: 'access_token',
value: 'abracadabra',
enabled: true,
secret: true
},
{
name: 'access_secret',
value: 'abracadabra',
enabled: false,
secret: true
}
]
};
const output = parser(input);
const expected = `vars {
url: http://localhost:3000
}
vars:secret [
access_token,
~access_secret
]
`;
expect(output).toEqual(expected);
});
it('should parse even if the only secret vars are present', () => {
const input = {
variables: [
{
name: 'token',
value: 'abracadabra',
enabled: true,
secret: true
}
]
};
const output = parser(input);
const expected = `vars:secret [
token
]
`;
expect(output).toEqual(expected);
});
2023-02-05 14:36:48 +01:00
});