Ghost/ghost/admin/tests/unit/transforms/unsplash-settings-test.js
Kevin Ansfield 6a9239974f Fixed missing Unsplash icons when API doesn't return an unsplash setting (#865)
closes https://github.com/TryGhost/Ghost/issues/9031

- add a default value `unsplash` value to the `setting` model so that Unsplash is activated when the server doesn't return an `unsplash` setting
- update the `unsplash-settings` transform to always deserialize or serialize to `{isActive: true}` when the value is blank or not parsable
- add acceptance regression test covering API not returning an `unplash` setting
- add unit tests for the `unsplash-settings` transform
2017-09-21 11:13:31 +02:00

47 lines
1.6 KiB
JavaScript

import {describe, it} from 'mocha';
import {expect} from 'chai';
import {setupTest} from 'ember-mocha';
describe('Unit: Transform: unsplash-settings', function () {
setupTest('transform:unsplash-settings', {
// Specify the other units that are required for this test.
// needs: ['transform:foo']
});
it('deserializes to default value when null', function () {
let serialized = null;
let result = this.subject().deserialize(serialized);
expect(result.isActive).to.be.true;
});
it('deserializes to default value when blank string', function () {
let serialized = '';
let result = this.subject().deserialize(serialized);
expect(result.isActive).to.be.true;
});
it('deserializes to default value when invalid JSON', function () {
let serialized = 'not JSON';
let result = this.subject().deserialize(serialized);
expect(result.isActive).to.be.true;
});
it('deserializes valid JSON object', function () {
let serialized = '{"isActive":false}';
let result = this.subject().deserialize(serialized);
expect(result.isActive).to.be.false;
});
it('serializes to JSON string', function () {
let deserialized = {isActive: false};
let result = this.subject().serialize(deserialized);
expect(result).to.equal('{"isActive":false}');
});
it('serializes to default value when blank', function () {
let deserialized = '';
let result = this.subject().serialize(deserialized);
expect(result).to.equal('{"isActive":true}');
});
});