Ghost/ghost/admin/tests/integration/services/slug-generator-test.js
Kevin Ansfield 983110d931 Switched from ember-cli-shims to new module imports (#779)
no issue

- add eslint-plugin-ember, configure no-old-shims rule
- run `eslint --fix` on `app`, `lib`, `mirage`, and `tests` to move imports to the new module imports
- further cleanup of Ember globals usage
- remove event-dispatcher initializer now that `canDispatchToEventManager` is deprecated
2017-08-22 14:53:26 +07:00

56 lines
1.5 KiB
JavaScript

import Pretender from 'pretender';
import {dasherize} from '@ember/string';
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {setupTest} from 'ember-mocha';
function stubSlugEndpoint(server, type, slug) {
server.get('/ghost/api/v0.1/slugs/:type/:slug/', function (request) {
expect(request.params.type).to.equal(type);
expect(request.params.slug).to.equal(slug);
return [
200,
{'Content-Type': 'application/json'},
JSON.stringify({slugs: [{slug: dasherize(slug)}]})
];
});
}
describe('Integration: Service: slug-generator', function () {
setupTest('service:slug-generator', {
integration: true
});
let server;
beforeEach(function () {
server = new Pretender();
});
afterEach(function () {
server.shutdown();
});
it('returns empty if no slug is provided', function (done) {
let service = this.subject();
service.generateSlug('post', '').then(function (slug) {
expect(slug).to.equal('');
done();
});
});
it('calls correct endpoint and returns correct data', function (done) {
let rawSlug = 'a test post';
stubSlugEndpoint(server, 'post', rawSlug);
let service = this.subject();
service.generateSlug('post', rawSlug).then(function (slug) {
expect(slug).to.equal(dasherize(rawSlug));
done();
});
});
});