Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
fix: Empty array payload (#112)
Browse files Browse the repository at this point in the history
* test: Add failing test

Should return an empty array, but helper returns a string

* fix: Return an empty array, rather than a string

If no IDs are provided to the buildRelationshipData() function, return an empty array

Fixes #108
  • Loading branch information
ynnoj authored Sep 12, 2017
1 parent 4234aba commit 80be7a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"commit": "git-cz",
"rollup": "rollup -c",
"test": "mocha --compilers js:babel-core/register test/unit/*"
"test": "mocha --compilers js:babel-core/register test/unit/* test/utils/*"
},
"main": "dist/moltin.cjs.js",
"module": "src/moltin.js",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function buildRelationshipData(type, ids) {
let data = [];

if (ids === null || ids.length === 0) {
return '[]';
return [];
}

if (typeof ids === 'string') {
Expand Down
19 changes: 19 additions & 0 deletions test/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from 'chai';
import { buildRelationshipData } from '../../src/utils/helpers';

describe('Build relationship payloads', () => {
it('should return an array of relationship key value pairings', () => {
const relationships = buildRelationshipData('category', ['123', '456']);

expect(relationships).to.deep.include.members([
{ type: 'category', id: '123' },
{ type: 'category', id: '456' },
]);
});

it('should return an empty array', () => {
const relationships = buildRelationshipData('category', null);

expect(relationships).to.be.an('array').that.is.empty;
});
});

0 comments on commit 80be7a3

Please sign in to comment.