Ghost/ghost/api-framework/test/util/options.test.js
Daniel Lockyer d5013199b3 Fixed handling objects as API input parameters
fix https://linear.app/tryghost/issue/SLO-155/paramsmap-is-not-a-function-an-unexpected-error-occurred-please-try

- in the case you provide an object to the API, this code will throw an
  error because it can't map over an object
- we can just assert that params should be an array and throw an error
  otherwise
2024-06-24 10:14:43 +02:00

32 lines
1.1 KiB
JavaScript

const optionsUtil = require('../../lib/utils/options');
describe('util/options', function () {
it('returns an array with empty string when no parameters are passed', function () {
optionsUtil.trimAndLowerCase().should.eql(['']);
});
it('returns single item array', function () {
optionsUtil.trimAndLowerCase('butter').should.eql(['butter']);
});
it('returns multiple items in array', function () {
optionsUtil.trimAndLowerCase('peanut, butter').should.eql(['peanut', 'butter']);
});
it('lowercases and trims items in the string', function () {
optionsUtil.trimAndLowerCase(' PeanUt, buTTer ').should.eql(['peanut', 'butter']);
});
it('accepts parameters in form of an array', function () {
optionsUtil.trimAndLowerCase([' PeanUt', ' buTTer ']).should.eql(['peanut', 'butter']);
});
it('throws error for invalid object input', function () {
try {
optionsUtil.trimAndLowerCase({name: 'peanut'});
} catch (err) {
err.message.should.eql('Params must be a string or array');
}
});
});