Ghost/ghost/admin/tests/unit/serializers/notification-test.js
Kevin Ansfield 2a1584af16 🐛 fix duplicate server alerts + default alert bg color (#242)
closes https://github.com/TryGhost/Ghost/issues/7305

The `location` property of server-side notifications was being ignored by the client and so wasn't being used to de-duplicate alerts.

- adds `key` attribute to `Notification` model
- adds a serializer for notifications that renames the `location` key sent by the server to `key`
- set the default background color of alerts to white so that alerts with no `type` set do not inherit the background color (useful in Ghost Desktop which has a transparent background color set)
2016-09-01 11:01:54 -05:00

48 lines
1.4 KiB
JavaScript

import { expect } from 'chai';
import { describeModel, it } from 'ember-mocha';
import run from 'ember-runloop';
import Pretender from 'pretender';
describeModel(
'notification',
'Unit: Serializer: notification',
{
// Specify the other units that are required for this test.
needs: ['serializer:notification']
},
function () {
let server;
beforeEach(function () {
server = new Pretender();
});
afterEach(function () {
server.shutdown();
});
it('converts location->key when deserializing', function () {
server.get('/notifications', function () {
let response = {
notifications: [{
id: 1,
dismissible: false,
status: 'alert',
type: 'info',
location: 'test.foo',
message: 'This is a test'
}]
};
return [200, {'Content-Type': 'application/json'}, JSON.stringify(response)];
});
return this.store().findAll('notification').then((notifications) => {
expect(notifications.get('length')).to.equal(1);
expect(notifications.get('firstObject.key')).to.equal('test.foo');
});
});
}
);