0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added unit tests for snippets

This commit is contained in:
Fabien "egg" O'Carroll 2023-12-14 16:55:14 +07:00
parent 82eea7afd2
commit e88c9f7c5e
2 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,37 @@
import assert from 'assert';
import {describe, it} from 'mocha';
import {Snippet} from './snippet.entity';
describe('Snippet Entity', () => {
let snippet: Snippet;
beforeEach(() => {
snippet = Snippet.create({
name: 'Test Snippet',
lexical: 'Test Lexical',
mobiledoc: 'Test Mobiledoc'
});
});
it('should create a snippet', () => {
assert(snippet instanceof Snippet);
assert.strictEqual(snippet.name, 'Test Snippet');
assert.strictEqual(snippet.lexical, 'Test Lexical');
assert.strictEqual(snippet.mobiledoc, 'Test Mobiledoc');
});
it('should update snippet name', () => {
snippet.name = 'Updated Snippet';
assert.strictEqual(snippet.name, 'Updated Snippet');
});
it('should update snippet lexical', () => {
snippet.lexical = 'Updated Lexical';
assert.strictEqual(snippet.lexical, 'Updated Lexical');
});
it('should update snippet mobiledoc', () => {
snippet.mobiledoc = 'Updated Mobiledoc';
assert.strictEqual(snippet.mobiledoc, 'Updated Mobiledoc');
});
});

View file

@ -0,0 +1,39 @@
import assert from 'assert';
import {SnippetsService} from './snippets.service';
import {SnippetsRepositoryInMemory} from '../../db/in-memory/snippets.repository.inmemory';
describe('SnippetService', () => {
it('Can do some basic service stuff', async () => {
const repository = new SnippetsRepositoryInMemory();
const service = new SnippetsService(repository);
const snippet = await service.create({
name: 'Test Snippet',
lexical: '',
mobiledoc: '{}'
});
const allSnippets = await service.getAll({});
assert(allSnippets[0].name === snippet.name);
const updated = await service.update(snippet.id, {
name: 'Updated Name'
});
assert(updated);
const pageOfSnippets = await service.getPage({
page: 1,
limit: 10
});
assert(pageOfSnippets.data[0].name === updated.name);
await service.delete(snippet.id);
const notFound = await service.getOne(snippet.id);
assert(notFound === null);
});
});