|
| 1 | +/** |
| 2 | + * row.test.ts - test rows in rowset container |
| 3 | + */ |
| 4 | + |
| 5 | +import { SQLiteCloudRowset, SQLiteCloudRow } from '../src/index' |
| 6 | +import { getChinookConnection } from './shared' |
| 7 | + |
| 8 | +describe('row', () => { |
| 9 | + it('can be accessed as a dictionary', done => { |
| 10 | + const connection = getChinookConnection() |
| 11 | + connection.sendCommands('SELECT * FROM tracks LIMIT 10;', (error, rowset) => { |
| 12 | + expect(rowset).toBeInstanceOf(SQLiteCloudRowset) |
| 13 | + |
| 14 | + const row = rowset[0] |
| 15 | + expect(row).toBeInstanceOf(SQLiteCloudRow) |
| 16 | + expect(rowset[0]).toMatchObject({ |
| 17 | + AlbumId: 1, |
| 18 | + Bytes: 11170334, |
| 19 | + Composer: 'Angus Young, Malcolm Young, Brian Johnson', |
| 20 | + GenreId: 1, |
| 21 | + MediaTypeId: 1, |
| 22 | + Milliseconds: 343719, |
| 23 | + Name: 'For Those About To Rock (We Salute You)', |
| 24 | + TrackId: 1, |
| 25 | + UnitPrice: 0.99 |
| 26 | + }) |
| 27 | + |
| 28 | + connection.close() |
| 29 | + done() |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + it('can be accessed as an array', done => { |
| 34 | + const connection = getChinookConnection() |
| 35 | + connection.sendCommands('SELECT * FROM tracks LIMIT 10;', (error, rowset) => { |
| 36 | + expect(rowset).toBeInstanceOf(SQLiteCloudRowset) |
| 37 | + |
| 38 | + const row = rowset[0] |
| 39 | + expect(row).toBeInstanceOf(SQLiteCloudRow) |
| 40 | + |
| 41 | + const rowData = row.getData() |
| 42 | + expect(rowData).toMatchObject([ |
| 43 | + 1, |
| 44 | + 'For Those About To Rock (We Salute You)', |
| 45 | + 1, |
| 46 | + 1, |
| 47 | + 1, |
| 48 | + 'Angus Young, Malcolm Young, Brian Johnson', |
| 49 | + 343719, |
| 50 | + 11170334, |
| 51 | + 0.99 |
| 52 | + ]) |
| 53 | + |
| 54 | + const rowColumns = rowset.metadata.columns.map((column: any) => column.name) |
| 55 | + expect(rowColumns).toMatchObject(['TrackId', 'Name', 'AlbumId', 'MediaTypeId', 'GenreId', 'Composer', 'Milliseconds', 'Bytes', 'UnitPrice']) |
| 56 | + |
| 57 | + connection.close() |
| 58 | + done() |
| 59 | + }) |
| 60 | + }) |
| 61 | +}) |
0 commit comments