Changeset View
Changeset View
Standalone View
Standalone View
web/database/queries/report-queries.test.js
- This file was added.
// @flow | |||||
import initSqlJs from 'sql.js'; | |||||
import { setupSQLiteDB } from './db-queries.js'; | |||||
import { | |||||
createReportTable, | |||||
getAllReports, | |||||
removeAllReports, | |||||
removeReports, | |||||
updateReport, | |||||
} from './report-queries.js'; | |||||
import { parseMultiStatementSQLiteResult } from '../utils/db-utils.js'; | |||||
describe('Report Store queries', () => { | |||||
let db; | |||||
beforeAll(async () => { | |||||
const SQL = await initSqlJs(); | |||||
db = new SQL.Database(); | |||||
createReportTable(db); | |||||
}); | |||||
beforeEach(() => { | |||||
setupSQLiteDB(db); | |||||
michal: Shouldn't we `setupSQLiteDB` in the `beforeAll`? | |||||
kamilAuthorUnsubmitted Done Inline Actionsbecause tests are concentrated on the reports table (created via createReportTable()) it doesn't really make any difference, I'll remove this kamil: because tests are concentrated on the `reports` table (created via `createReportTable()`) it… | |||||
db.exec(` | |||||
INSERT INTO reports VALUES ("1", "{report_content_1"); | |||||
INSERT INTO reports VALUES ("2", "{report_content_2}"); | |||||
`); | |||||
}); | |||||
afterEach(() => { | |||||
db.exec(`DELETE FROM reports`); | |||||
}); | |||||
it('should create table', () => { | |||||
const res = db.exec(`PRAGMA table_info(reports);`); | |||||
const [parsedRes] = parseMultiStatementSQLiteResult(res); | |||||
expect(parsedRes).toHaveLength(2); | |||||
expect(parsedRes).toEqual( | |||||
expect.arrayContaining([ | |||||
expect.objectContaining({ | |||||
name: 'id', | |||||
type: 'TEXT', | |||||
}), | |||||
expect.objectContaining({ | |||||
name: 'report', | |||||
type: 'TEXT', | |||||
}), | |||||
]), | |||||
); | |||||
}); | |||||
it('should return all reports', () => { | |||||
const reports = getAllReports(db); | |||||
expect(reports).toHaveLength(2); | |||||
}); | |||||
it('should remove all reports', () => { | |||||
removeAllReports(db); | |||||
const reports = getAllReports(db); | |||||
expect(reports).toHaveLength(0); | |||||
}); | |||||
it('should insert not existing report', () => { | |||||
const id = '3'; | |||||
const report = '{some_content}'; | |||||
updateReport(db, id, report); | |||||
const reports = getAllReports(db); | |||||
expect(reports).toHaveLength(3); | |||||
expect(reports).toContainEqual({ id, report }); | |||||
}); | |||||
it('should reports', () => { | |||||
michalUnsubmitted Not Done Inline ActionsI think you missed the name michal: I think you missed the name | |||||
kamilAuthorUnsubmitted Done Inline Actionsoversight, fixing kamil: oversight, fixing | |||||
const id = '2'; | |||||
removeReports(db, [id]); | |||||
const reports = getAllReports(db); | |||||
expect(reports).toHaveLength(1); | |||||
expect(reports).not.toContain( | |||||
expect.objectContaining({ | |||||
id, | |||||
}), | |||||
); | |||||
}); | |||||
}); |
Shouldn't we setupSQLiteDB in the beforeAll?