40 lines
2.2 KiB
JavaScript
40 lines
2.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { bannerOf, badgeOf, planText, needsName, signature } from './schema-model.js';
|
|
|
|
const problem = { state: 'problems', production: false, problems: [{ code: 'entity_without_table', message: 'The entity Xxxxa has no table: no migration creates it.' }],
|
|
fixes: [{ id: 'all', label: 'Fix everything', primary: true }, { id: 'diff', label: 'Generate a migration' }], plan: [{ id: 'diff', label: 'Generate a migration' }, { id: 'migrate', label: 'Apply migrations' }] };
|
|
|
|
test('a problem makes a banner with its lines and fixes', () => {
|
|
const b = bannerOf(problem);
|
|
assert.equal(b.level, 'error');
|
|
assert.deepEqual(b.lines, ['The entity Xxxxa has no table: no migration creates it.']);
|
|
assert.equal(b.fixes[0].id, 'all');
|
|
});
|
|
|
|
test('nothing wrong, checking, or dismissed: no banner', () => {
|
|
assert.equal(bannerOf({ state: 'ok', problems: [] }), null);
|
|
assert.equal(bannerOf({ state: 'checking' }), null);
|
|
assert.equal(bannerOf(null), null);
|
|
assert.equal(bannerOf(problem, signature(problem)), null);
|
|
assert.notEqual(bannerOf({ ...problem, problems: [{ code: 'pending_migrations', message: '2 migrations are not applied.' }] }, signature(problem)), null);
|
|
});
|
|
|
|
test('pending migrations and an unreachable server are warnings', () => {
|
|
assert.equal(bannerOf({ state: 'problems', problems: [{ code: 'unreachable', message: 'x' }], fixes: [] }).level, 'warning');
|
|
assert.equal(bannerOf({ state: 'problems', problems: [{ code: 'pending_migrations', message: 'x' }], fixes: [] }).level, 'warning');
|
|
});
|
|
|
|
test('the badge counts the problems', () => {
|
|
assert.deepEqual(badgeOf(problem), { kind: 'problem', count: 1 });
|
|
assert.equal(badgeOf({ state: 'ok', problems: [] }).kind, 'ok');
|
|
assert.equal(badgeOf({ state: 'checking' }).kind, 'checking');
|
|
assert.equal(badgeOf(null).kind, '');
|
|
});
|
|
|
|
test('the plan is numbered and production asks for the name', () => {
|
|
assert.equal(planText(problem.plan), '1. Generate a migration\n2. Apply migrations');
|
|
assert.equal(needsName('migrate', { production: true }), true);
|
|
assert.equal(needsName('migrate', { production: false }), false);
|
|
assert.equal(needsName('openDoctrine', { production: true }), false);
|
|
});
|