mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Refactored collections unit test suite
refs https://github.com/TryGhost/Team/issues/3167 - Duplicate service initialization was getting annoying
This commit is contained in:
parent
f3f3d58acf
commit
7d926dd30b
1 changed files with 7 additions and 14 deletions
|
@ -4,16 +4,18 @@ import {CollectionsService} from '../src/index';
|
||||||
import {CollectionsRepositoryInMemory} from '../src/CollectionsRepositoryInMemory';
|
import {CollectionsRepositoryInMemory} from '../src/CollectionsRepositoryInMemory';
|
||||||
|
|
||||||
describe('collections', function () {
|
describe('collections', function () {
|
||||||
it('Instantiates a CollectionsService', function () {
|
let collectionsService: CollectionsService;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
const repository = new CollectionsRepositoryInMemory();
|
const repository = new CollectionsRepositoryInMemory();
|
||||||
const collectionsService = new CollectionsService({repository});
|
collectionsService = new CollectionsService({repository});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Instantiates a CollectionsService', function () {
|
||||||
assert.ok(collectionsService, 'CollectionsService should initialize');
|
assert.ok(collectionsService, 'CollectionsService should initialize');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can do CRUD operations on a collection', async function () {
|
it('Can do CRUD operations on a collection', async function () {
|
||||||
const repository = new CollectionsRepositoryInMemory();
|
|
||||||
const collectionsService = new CollectionsService({repository});
|
|
||||||
|
|
||||||
const savedCollection = await collectionsService.save({
|
const savedCollection = await collectionsService.save({
|
||||||
title: 'testing collections',
|
title: 'testing collections',
|
||||||
description: 'testing collections description',
|
description: 'testing collections description',
|
||||||
|
@ -39,9 +41,6 @@ describe('collections', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can create a collection with predefined ID', async function () {
|
it('Can create a collection with predefined ID', async function () {
|
||||||
const repository = new CollectionsRepositoryInMemory();
|
|
||||||
const collectionsService = new CollectionsService({repository});
|
|
||||||
|
|
||||||
const id = new ObjectID();
|
const id = new ObjectID();
|
||||||
const savedCollection = await collectionsService.save({
|
const savedCollection = await collectionsService.save({
|
||||||
id: id.toHexString()
|
id: id.toHexString()
|
||||||
|
@ -51,9 +50,6 @@ describe('collections', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can create a collection with predefined ObjectID instance', async function () {
|
it('Can create a collection with predefined ObjectID instance', async function () {
|
||||||
const repository = new CollectionsRepositoryInMemory();
|
|
||||||
const collectionsService = new CollectionsService({repository});
|
|
||||||
|
|
||||||
const id = new ObjectID();
|
const id = new ObjectID();
|
||||||
const savedCollection = await collectionsService.save({
|
const savedCollection = await collectionsService.save({
|
||||||
id: id
|
id: id
|
||||||
|
@ -63,9 +59,6 @@ describe('collections', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Throws an error when trying to save a collection with an invalid ID', async function () {
|
it('Throws an error when trying to save a collection with an invalid ID', async function () {
|
||||||
const repository = new CollectionsRepositoryInMemory();
|
|
||||||
const collectionsService = new CollectionsService({repository});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await collectionsService.save({
|
await collectionsService.save({
|
||||||
id: 12345
|
id: 12345
|
||||||
|
|
Loading…
Add table
Reference in a new issue