2016-01-15 18:43:16 +03:00
|
|
|
import Pretender from 'pretender';
|
2021-02-05 12:12:26 +03:00
|
|
|
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {dasherize} from '@ember/string';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {expect} from 'chai';
|
|
|
|
import {setupTest} from 'ember-mocha';
|
2016-01-15 18:43:16 +03:00
|
|
|
|
|
|
|
function stubSlugEndpoint(server, type, slug) {
|
2021-02-05 12:12:26 +03:00
|
|
|
server.get(`${ghostPaths().apiRoot}/slugs/:type/:slug/`, function (request) {
|
2016-01-15 18:43:16 +03:00
|
|
|
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)}]})
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('Integration: Service: slug-generator', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
setupTest();
|
2016-01-15 18:43:16 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
let server;
|
2016-01-15 18:43:16 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
server = new Pretender();
|
|
|
|
});
|
2016-01-15 18:43:16 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
afterEach(function () {
|
|
|
|
server.shutdown();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty if no slug is provided', function (done) {
|
2019-05-13 15:43:53 +03:00
|
|
|
let service = this.owner.lookup('service:slug-generator');
|
2016-01-15 18:43:16 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
service.generateSlug('post', '').then(function (slug) {
|
|
|
|
expect(slug).to.equal('');
|
|
|
|
done();
|
2016-01-15 18:43:16 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2016-01-15 18:43:16 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('calls correct endpoint and returns correct data', function (done) {
|
|
|
|
let rawSlug = 'a test post';
|
|
|
|
stubSlugEndpoint(server, 'post', rawSlug);
|
2016-01-15 18:43:16 +03:00
|
|
|
|
2019-05-13 15:43:53 +03:00
|
|
|
let service = this.owner.lookup('service:slug-generator');
|
2016-01-15 18:43:16 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
service.generateSlug('post', rawSlug).then(function (slug) {
|
|
|
|
expect(slug).to.equal(dasherize(rawSlug));
|
|
|
|
done();
|
2016-01-15 18:43:16 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|