mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 05:50:35 +03:00
c4c48d4104
refs https://github.com/TryGhost/Admin/pull/2209 - `miragejs` has been extracted to a framework-independent library, the re-exports of `miragejs` elements in `ember-cli-mirage` have been deprecated making our test logs very noisy - added `miragejs` as a top-level dependency - updated all relevant imports to pull from `miragejs` instead of `ember-cli-mirage`
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
import {Response} from 'miragejs';
|
|
|
|
let themeCount = 1;
|
|
|
|
export default function mockThemes(server) {
|
|
server.get('/themes');
|
|
|
|
server.post('/themes/upload/', function ({themes}) {
|
|
// pretender/mirage doesn't currently process FormData so we can't use
|
|
// any info passed in through the request
|
|
let theme = {
|
|
name: `test-${themeCount}`,
|
|
package: {
|
|
name: `Test ${themeCount}`,
|
|
version: '0.1'
|
|
}
|
|
};
|
|
|
|
themeCount += 1;
|
|
|
|
theme = themes.create(theme);
|
|
|
|
return {themes: [theme]};
|
|
});
|
|
|
|
server.del('/themes/:theme/', function ({themes}, {params}) {
|
|
themes.findBy({name: params.theme}).destroy();
|
|
|
|
return new Response(204);
|
|
});
|
|
|
|
server.put('/themes/:theme/activate/', function ({themes}, {params}) {
|
|
themes.all().update('active', false);
|
|
let theme = themes.findBy({name: params.theme}).update({active: true});
|
|
|
|
return {themes: [theme]};
|
|
});
|
|
|
|
server.post('/themes/install/', function ({themes}, {queryParams}) {
|
|
themes.all().update('active', false);
|
|
|
|
const themeName = queryParams.ref.replace('TryGhost/', '');
|
|
|
|
let theme = themes.findBy({name: themeName});
|
|
if (theme) {
|
|
theme.update({active: true});
|
|
} else {
|
|
theme = themes.create({
|
|
name: themeName,
|
|
package: {
|
|
name: themeName,
|
|
version: '0.1'
|
|
}
|
|
});
|
|
}
|
|
|
|
return {themes: [theme]};
|
|
});
|
|
}
|