Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const sirenParserTestingConfig = [
languageOptions: {
sourceType: 'module',
},
rules: {
'prefer-arrow-callback': 'off',
},
}
]

Expand Down
110 changes: 55 additions & 55 deletions test/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import sinonChai from 'sinon-chai';

use(sinonChai);

describe('Action', function() {
describe('Action', () => {
let
resource,
sandbox,
siren;

beforeEach(function() {
beforeEach(() => {
resource = {
name: 'foo',
href: 'bar'
Expand All @@ -22,140 +22,140 @@ describe('Action', function() {
sandbox.stub(console, 'warn');
});

afterEach(function() {
afterEach(() => {
sandbox.restore();
});

function buildAction() {
return new Action(resource);
}

it('should auto-instantiate', function() {
it('should auto-instantiate', () => {
expect(Action(resource)).to.be.an.instanceof(Action);
});

it('should require the action be an object', function() {
it('should require the action be an object', () => {
resource = 1;
expect(buildAction.bind()).to.throw('action must be an object, got 1');
});

describe('name', function() {
it('should require a name', function() {
describe('name', () => {
it('should require a name', () => {
resource.name = undefined;
expect(buildAction.bind()).to.throw('action.name must be a string, got undefined');
});

it('should require name be a string', function() {
it('should require name be a string', () => {
resource.name = 1;
expect(buildAction.bind()).to.throw('action.name must be a string, got 1');
});

it('should parse name', function() {
it('should parse name', () => {
siren = buildAction();
expect(siren.name).to.equal('foo');
});
});

describe('href', function() {
it('should require a href', function() {
describe('href', () => {
it('should require a href', () => {
resource.href = undefined;
expect(buildAction.bind()).to.throw('action.href must be a string, got undefined');
});

it('should require href be a string', function() {
it('should require href be a string', () => {
resource.href = 1;
expect(buildAction.bind()).to.throw('action.href must be a string, got 1');
});

it('should parse href', function() {
it('should parse href', () => {
siren = buildAction();
expect(siren.href).to.equal('bar');
});
});

describe('class', function() {
it('should parse class', function() {
describe('class', () => {
it('should parse class', () => {
resource.class = [];
siren = buildAction();
expect(siren.class).to.be.an.instanceof(Array);
});

it('should require class be an array, if supplied', function() {
it('should require class be an array, if supplied', () => {
resource.class = 1;
expect(buildAction.bind()).to.throw('action.class must be an array or undefined, got 1');
});
});

describe('method', function() {
it('should parse method', function() {
describe('method', () => {
it('should parse method', () => {
resource.method = 'baz';
siren = buildAction();
expect(siren.method).to.equal('baz');
});

it('should default to GET', function() {
it('should default to GET', () => {
siren = buildAction();
expect(siren.method).to.equal('GET');
});

it('should require method be a string, if supplied', function() {
it('should require method be a string, if supplied', () => {
resource.method = 1;
expect(buildAction.bind(undefined, resource)).to.throw('action.method must be a string or undefined, got 1');
});
});

describe('title', function() {
it('should parse title', function() {
describe('title', () => {
it('should parse title', () => {
resource.title = 'baz';
siren = buildAction();
expect(siren.title).to.equal('baz');
});

it('should require title be a string, if supplied', function() {
it('should require title be a string, if supplied', () => {
resource.title = 1;
expect(buildAction.bind(undefined, resource)).to.throw('action.title must be a string or undefined, got 1');
});
});

describe('type', function() {
it('should parse type', function() {
describe('type', () => {
it('should parse type', () => {
resource.type = 'baz';
siren = buildAction();
expect(siren.type).to.equal('baz');
});

it('should default to application/x-www-form-urlencoded', function() {
it('should default to application/x-www-form-urlencoded', () => {
siren = buildAction();
expect(siren.type).to.equal('application/x-www-form-urlencoded');
});

it('should require type be a string, if supplied', function() {
it('should require type be a string, if supplied', () => {
resource.type = 1;
expect(buildAction.bind(undefined, resource)).to.throw('action.type must be a string or undefined, got 1');
});
});

describe('fields', function() {
it('should parse fields', function() {
describe('fields', () => {
it('should parse fields', () => {
resource.fields = [];
siren = buildAction();
expect(siren.fields).to.be.an.instanceof(Array);
});

it('should require fields be an array, if supplied', function() {
it('should require fields be an array, if supplied', () => {
resource.fields = 1;
expect(buildAction.bind(undefined, resource)).to.throw('action.fields must be an array or undefined, got 1');
});

it('should be able to determine if an Action has a given Field', function() {
it('should be able to determine if an Action has a given Field', () => {
resource.fields = [{
name: 'foo'
}];
siren = buildAction();
expect(siren.hasField('foo')).to.be.true;
});

it('should be able to retrieve fields based off their name', function() {
it('should be able to retrieve fields based off their name', () => {
resource.fields = [{
name: 'foo',
title: 'bar'
Expand All @@ -164,7 +164,7 @@ describe('Action', function() {
expect(siren.getField('foo')).to.have.property('title', 'bar');
});

it('should be able to use field helper methods', function() {
it('should be able to use field helper methods', () => {
resource.fields = [{
class: ['abc'],
name: 'foo',
Expand All @@ -175,25 +175,25 @@ describe('Action', function() {
});
});

describe('toJSON', function() {
describe('toJSON', () => {
function toJSON() {
return JSON.stringify(buildAction());
}

it('should stringify name and href', function() {
it('should stringify name and href', () => {
expect(toJSON()).to.equal(
'{"name":"foo","href":"bar","method":"GET","type":"application/x-www-form-urlencoded"}'
);
});

it('should stringify class', function() {
it('should stringify class', () => {
resource.class = ['abc'];
expect(toJSON()).to.equal(
'{"name":"foo","href":"bar","class":["abc"],"method":"GET","type":"application/x-www-form-urlencoded"}'
);
});

it('should stringify fields', function() {
it('should stringify fields', () => {
resource.fields = [{
name: 'foo',
title: 'bar'
Expand All @@ -204,10 +204,10 @@ describe('Action', function() {
});
});

describe('Helper functions', function() {
describe('has...', function() {
describe('Class', function() {
it('should be able to determine if an action has a given class', function() {
describe('Helper functions', () => {
describe('has...', () => {
describe('Class', () => {
it('should be able to determine if an action has a given class', () => {
resource.class = ['foo'];
siren = buildAction();
expect(siren.hasClass('foo')).to.be.true;
Expand All @@ -224,8 +224,8 @@ describe('Action', function() {
});
});

describe('Field', function() {
it('hasFieldByName (hasField)', function() {
describe('Field', () => {
it('hasFieldByName (hasField)', () => {
resource.fields = [{
name: 'foo'
}];
Expand All @@ -243,7 +243,7 @@ describe('Action', function() {
expect(siren.hasField('foo')).to.be.false;
});

it('hasFieldByClass', function() {
it('hasFieldByClass', () => {
resource.fields = [{
name: 'foo',
class: ['bar']
Expand All @@ -262,7 +262,7 @@ describe('Action', function() {
expect(siren.hasFieldByClass('bar')).to.be.false;
});

it('hasFieldByType', function() {
it('hasFieldByType', () => {
resource.fields = [{
name: 'foo',
type: 'text'
Expand All @@ -283,9 +283,9 @@ describe('Action', function() {
});
});

describe('get...', function() {
describe('Field', function() {
beforeEach(function() {
describe('get...', () => {
describe('Field', () => {
beforeEach(() => {
resource.fields = [{
name: 'foo',
title: 'bar',
Expand All @@ -310,7 +310,7 @@ describe('Action', function() {
siren = buildAction();
});

it('getFieldByName (getField)', function() {
it('getFieldByName (getField)', () => {
expect(siren.getField('foo')).to.have.property('title', 'bar');
expect(siren.getField('nope')).to.be.undefined;
expect(siren.getField(undefined)).to.be.undefined;
Expand All @@ -321,7 +321,7 @@ describe('Action', function() {
expect(siren.getField(/bar/)).to.be.undefined;
});

it('getFieldByClass', function() {
it('getFieldByClass', () => {
expect(siren.getFieldByClass('baz')).to.have.property('title', 'bar');
expect(siren.getFieldByClass('nope')).to.be.undefined;
expect(siren.getFieldByClass(undefined)).to.be.undefined;
Expand All @@ -332,7 +332,7 @@ describe('Action', function() {
expect(siren.getFieldByClass(/foo/)).to.be.undefined;
});

it('getFieldsByClass', function() {
it('getFieldsByClass', () => {
expect(siren.getFieldsByClass('baz')).to.be.an.instanceof(Array).with.lengthOf(2);
expect(siren.getFieldsByClass('nope')).to.be.an.instanceof(Array).and.to.be.empty;
expect(siren.getFieldsByClass(undefined)).to.be.an.instanceof(Array).and.to.be.empty;
Expand All @@ -343,7 +343,7 @@ describe('Action', function() {
expect(siren.getFieldsByClass(/foo/)).to.be.an.instanceof(Array).and.to.be.empty;
});

it('getFieldByClasses', function() {
it('getFieldByClasses', () => {
expect(siren.getFieldByClasses(['bonk', 'bork'])).to.have.property('name', 'foo3');
expect(siren.getFieldByClasses([/bonk/, /bork/])).to.have.property('name', 'foo3');
expect(siren.getFieldByClasses(['bonk', /bork/])).to.have.property('name', 'foo3');
Expand All @@ -355,7 +355,7 @@ describe('Action', function() {
expect(siren.getFieldByClasses([null])).to.be.undefined;
});

it('getFieldsByClasses', function() {
it('getFieldsByClasses', () => {
expect(siren.getFieldsByClasses(['bonk', 'bork'])).to.be.an.instanceof(Array).with.lengthOf(2);
expect(siren.getFieldsByClasses([/bonk/, /bork/])).to.be.an.instanceof(Array).with.lengthOf(2);
expect(siren.getFieldsByClasses(['bonk', /bork/])).to.be.an.instanceof(Array).with.lengthOf(2);
Expand All @@ -367,7 +367,7 @@ describe('Action', function() {
expect(siren.getFieldsByClasses([null])).to.be.an.instanceof(Array).and.to.be.empty;
});

it('getFieldByType', function() {
it('getFieldByType', () => {
expect(siren.getFieldByType('text')).to.have.property('title', 'bar');
expect(siren.getFieldByType('nope')).to.be.undefined;
expect(siren.getFieldByType(undefined)).to.be.undefined;
Expand All @@ -378,7 +378,7 @@ describe('Action', function() {
expect(siren.getFieldByType(/nope/)).to.be.undefined;
});

it('getFieldsByType', function() {
it('getFieldsByType', () => {
expect(siren.getFieldsByType('text')).to.be.an.instanceof(Array).with.lengthOf(2);
expect(siren.getFieldsByType('nope')).to.be.an.instanceof(Array).and.to.be.empty;
expect(siren.getFieldsByType(undefined)).to.be.an.instanceof(Array).and.to.be.empty;
Expand Down
Loading