Ghost/ghost/admin/app/transforms/unsplash-settings.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

29 lines
752 B
JavaScript

/* eslint-disable camelcase */
import Transform from 'ember-data/transform';
import UnsplashObject from 'ghost-admin/models/unsplash-integration';
const DEFAULT_SETTINGS = {
isActive: true
};
export default Transform.extend({
deserialize(serialized) {
if (serialized) {
let settingsObject;
try {
settingsObject = JSON.parse(serialized) || DEFAULT_SETTINGS;
} catch (e) {
settingsObject = DEFAULT_SETTINGS;
}
return UnsplashObject.create(settingsObject);
}
return DEFAULT_SETTINGS;
},
serialize(deserialized) {
return deserialized ? JSON.stringify(deserialized) : JSON.stringify(DEFAULT_SETTINGS);
}
});