Skip to content

Commit a61e9c9

Browse files
More statement coverage
1 parent 052fa08 commit a61e9c9

File tree

4 files changed

+98
-48
lines changed

4 files changed

+98
-48
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,5 @@ lib/
123123
.env
124124
test/assets/testing.db
125125

126-
tools/
126+
tools/
127+
test/assets/testing-*.db

test/connection.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ describe('connection', () => {
263263
done()
264264
})
265265
},
266-
EXTRA_LONG_TIMEOUT
266+
LONG_TIMEOUT
267267
)
268268
})
269269

test/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as dotenv from 'dotenv'
1212
import { SQLiteCloudConnection } from '../src'
1313
dotenv.config()
1414

15-
export const LONG_TIMEOUT = 100 * 1000 // 100 seconds
15+
export const LONG_TIMEOUT = 1 * 60 * 1000 // 1 minute
1616
export const EXTRA_LONG_TIMEOUT = 15 * 60 * 1000 // 15 minutes
1717

1818
/** Will warn if a query or other basic operation is slower than this */

test/statement.test.ts

Lines changed: 94 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,104 @@
33
*/
44

55
import { SQLiteCloudRowset } from '../src'
6-
import { RowCallback, RowCountCallback } from '../src/types'
6+
import { RowCallback, RowCountCallback, SQLiteCloudError } from '../src/types'
77
import { getChinookDatabase } from './shared'
88

9-
it('Database.prepare without initial bindings', done => {
9+
describe('Database.prepare', () => {
10+
it('without incorrect bindings', done => {
11+
const chinook = getChinookDatabase()
12+
expect(chinook).toBeDefined()
13+
14+
// two bindings, but only one is provided...
15+
const statement = chinook.prepare('SELECT * FROM tracks WHERE albumId = ? and trackId = ?;', 1, (err: Error, results: any) => {
16+
expect(err).toBeInstanceOf(SQLiteCloudError)
17+
18+
chinook.close()
19+
done()
20+
})
21+
})
22+
23+
it('without initial bindings', done => {
24+
const chinook = getChinookDatabase()
25+
expect(chinook).toBeDefined()
26+
const statement = chinook.prepare('SELECT * FROM tracks WHERE albumId = ?;', (err: Error, results: any) => {
27+
expect(err).toBeNull()
28+
})
29+
30+
statement.all(3, (error, rows) => {
31+
expect(error).toBeNull()
32+
expect(rows).toBeDefined()
33+
expect(rows).toHaveLength(3)
34+
expect(rows).toBeInstanceOf(SQLiteCloudRowset)
35+
expect(rows).toMatchObject([
36+
{
37+
AlbumId: 3,
38+
Bytes: 3990994,
39+
Composer: 'F. Baltes, S. Kaufman, U. Dirkscneider & W. Hoffman',
40+
GenreId: 1,
41+
MediaTypeId: 2,
42+
Milliseconds: 230619,
43+
Name: 'Fast As a Shark',
44+
TrackId: 3,
45+
UnitPrice: 0.99
46+
},
47+
{
48+
AlbumId: 3,
49+
Bytes: 4331779,
50+
Composer: 'F. Baltes, R.A. Smith-Diesel, S. Kaufman, U. Dirkscneider & W. Hoffman',
51+
GenreId: 1,
52+
MediaTypeId: 2,
53+
Milliseconds: 252051,
54+
Name: 'Restless and Wild',
55+
TrackId: 4,
56+
UnitPrice: 0.99
57+
},
58+
{
59+
AlbumId: 3,
60+
Bytes: 6290521,
61+
Composer: 'Deaffy & R.A. Smith-Diesel',
62+
GenreId: 1,
63+
MediaTypeId: 2,
64+
Milliseconds: 375418,
65+
Name: 'Princess of the Dawn',
66+
TrackId: 5,
67+
UnitPrice: 0.99
68+
}
69+
])
70+
71+
chinook.close(error => {
72+
expect(error).toBeNull()
73+
done()
74+
})
75+
})
76+
})
77+
})
78+
79+
it('Statement.bind', done => {
1080
const chinook = getChinookDatabase()
1181
expect(chinook).toBeDefined()
1282
const statement = chinook.prepare('SELECT * FROM tracks WHERE albumId = ?;', (err: Error, results: any) => {
1383
expect(err).toBeNull()
1484
})
1585

16-
statement.all(3, (error, rows) => {
86+
statement.bind(3, (error: Error) => {
1787
expect(error).toBeNull()
18-
expect(rows).toBeDefined()
19-
expect(rows).toHaveLength(3)
20-
expect(rows).toBeInstanceOf(SQLiteCloudRowset)
21-
expect(rows).toMatchObject([
22-
{
23-
AlbumId: 3,
24-
Bytes: 3990994,
25-
Composer: 'F. Baltes, S. Kaufman, U. Dirkscneider & W. Hoffman',
26-
GenreId: 1,
27-
MediaTypeId: 2,
28-
Milliseconds: 230619,
29-
Name: 'Fast As a Shark',
30-
TrackId: 3,
31-
UnitPrice: 0.99
32-
},
33-
{
34-
AlbumId: 3,
35-
Bytes: 4331779,
36-
Composer: 'F. Baltes, R.A. Smith-Diesel, S. Kaufman, U. Dirkscneider & W. Hoffman',
37-
GenreId: 1,
38-
MediaTypeId: 2,
39-
Milliseconds: 252051,
40-
Name: 'Restless and Wild',
41-
TrackId: 4,
42-
UnitPrice: 0.99
43-
},
44-
{
45-
AlbumId: 3,
46-
Bytes: 6290521,
47-
Composer: 'Deaffy & R.A. Smith-Diesel',
48-
GenreId: 1,
49-
MediaTypeId: 2,
50-
Milliseconds: 375418,
51-
Name: 'Princess of the Dawn',
52-
TrackId: 5,
53-
UnitPrice: 0.99
54-
}
55-
])
5688

57-
chinook.close(error => {
89+
statement.all((error, rows) => {
5890
expect(error).toBeNull()
59-
done()
91+
expect(rows).toBeDefined()
92+
expect(rows).toHaveLength(3)
93+
expect(rows).toBeInstanceOf(SQLiteCloudRowset)
94+
95+
// missing binding
96+
statement.bind((error: Error) => {
97+
expect(error).toBeInstanceOf(SQLiteCloudError)
98+
99+
chinook.close(error => {
100+
expect(error).toBeNull()
101+
done()
102+
})
103+
})
60104
})
61105
})
62106
})
@@ -148,7 +192,12 @@ it('Statement.run', done => {
148192
statement.run(1, error => {
149193
expect(error).toBeNull()
150194

151-
chinook.close()
152-
done()
195+
// run again but use same binding this time
196+
statement.run(error => {
197+
expect(error).toBeNull()
198+
199+
chinook.close()
200+
done()
201+
})
153202
})
154203
})

0 commit comments

Comments
 (0)