u
This commit is contained in:
41
scripts/test-printeragent.js
Normal file
41
scripts/test-printeragent.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import LibDashStore from '../src/index.js';
|
||||
import { BetterSqlite3Provider } from '../src/providers/sqlite3/index.js';
|
||||
|
||||
const tempDir = mkdtempSync(join(tmpdir(), 'dash-printeragent-test-'));
|
||||
const provider = new BetterSqlite3Provider({ filename: join(tempDir, 'test.db'), storageDir: join(tempDir, 'storage') });
|
||||
await provider.initialize();
|
||||
const store = await new LibDashStore(provider);
|
||||
|
||||
try {
|
||||
const googleAuthId = await store.google_auth.add('printeragent-tester@example.com');
|
||||
const company = await store.company.create({ name: 'PA GmbH', iso639: 'de', taxrate: 19, reducedtaxrate: 7, googleAuthId });
|
||||
await store.google_auth.setSelectedCompany(googleAuthId, company.id);
|
||||
|
||||
assert.deepEqual(await store.printeragent.list(googleAuthId), []);
|
||||
await assert.rejects(store.printeragent.create(googleAuthId, { name: ' ', pairingpin: '1' }), /Invalid printeragent/);
|
||||
|
||||
const a = await store.printeragent.create(googleAuthId, { name: ' Bar ', pairingpin: '123456' });
|
||||
assert.equal(a.name, 'Bar');
|
||||
assert.equal(a.pairingpin, '123456');
|
||||
assert.equal(a.token, null);
|
||||
assert.equal(a.companyId, company.id);
|
||||
assert.ok(a.updatedAt);
|
||||
|
||||
const b = await store.printeragent.update(googleAuthId, { id: a.id, name: 'Kitchen' });
|
||||
assert.equal(b.name, 'Kitchen');
|
||||
await assert.rejects(store.printeragent.update(googleAuthId, { id: 9999, name: 'x' }), /Printeragent not found/);
|
||||
await assert.rejects(store.printeragent.update(googleAuthId, { id: a.id, name: '' }), /Invalid printeragent/);
|
||||
|
||||
assert.equal((await store.printeragent.list(googleAuthId)).length, 1);
|
||||
await store.printeragent.delete(googleAuthId, a.id);
|
||||
await assert.rejects(store.printeragent.delete(googleAuthId, a.id), /Printeragent not found/);
|
||||
assert.deepEqual(await store.printeragent.list(googleAuthId), []);
|
||||
console.log('printeragent OK');
|
||||
} finally {
|
||||
await provider.close?.();
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
Reference in New Issue
Block a user