mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 09:22:49 +03:00
4e2a00b6e6
closes https://github.com/TryGhost/Team/issues/3166 - The collections service contains CRUD logic to manage collection entities through: save, getById, getAll, and destroy methods.
40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
import assert from 'assert';
|
|
import {CollectionsService} from '../src/index';
|
|
import {CollectionsRepositoryInMemory} from '../src/CollectionsRepositoryInMemory';
|
|
|
|
describe('collections', function () {
|
|
it('Instantiates a CollectionsService', function () {
|
|
const repository = new CollectionsRepositoryInMemory();
|
|
const collectionsService = new CollectionsService({repository});
|
|
assert.ok(collectionsService, 'CollectionsService should initialize');
|
|
});
|
|
|
|
it('Can do CRUD operations on a collection', async function () {
|
|
const repository = new CollectionsRepositoryInMemory();
|
|
const collectionsService = new CollectionsService({repository});
|
|
|
|
await collectionsService.save({
|
|
id: 'test_id_1',
|
|
title: 'testing collections',
|
|
description: 'testing collections description',
|
|
type: 'manual',
|
|
filter: null,
|
|
feature_image: null,
|
|
deleted: false
|
|
});
|
|
|
|
const createdCollection = await collectionsService.getById('test_id_1');
|
|
|
|
assert.ok(createdCollection, 'Collection should be saved');
|
|
assert.equal(createdCollection.title, 'testing collections', 'Collection title should match');
|
|
|
|
const allCollections = await collectionsService.getAll();
|
|
assert.equal(allCollections.length, 1, 'There should be one collection');
|
|
|
|
await collectionsService.destroy('test_id_1');
|
|
const deletedCollection = await collectionsService.getById('test_id_1');
|
|
|
|
assert.equal(deletedCollection, null, 'Collection should be deleted');
|
|
});
|
|
});
|