-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add oneFirst and maybeOneFirst; remove firstColumn helper
BREAKING CHANGE: removed firstColumn helper
- Loading branch information
Showing
6 changed files
with
249 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// @flow | ||
|
||
/* eslint-disable flowtype/no-weak-types */ | ||
|
||
import test from 'ava'; | ||
import sinon from 'sinon'; | ||
import { | ||
maybeOneFirst, | ||
DataIntegrityError | ||
} from '../../src'; | ||
|
||
test('returns the first row', async (t) => { | ||
const stub = sinon.stub().returns({ | ||
rows: [ | ||
{ | ||
foo: 1 | ||
} | ||
] | ||
}); | ||
|
||
const connection: any = { | ||
query: stub | ||
}; | ||
|
||
const result = await maybeOneFirst(connection, {}, 'SELECT foo FROM bar'); | ||
|
||
t.deepEqual(result, 1); | ||
}); | ||
|
||
test('returns null if no results', async (t) => { | ||
const stub = sinon.stub().returns({ | ||
rows: [] | ||
}); | ||
|
||
const connection: any = { | ||
query: stub | ||
}; | ||
|
||
const result = await maybeOneFirst(connection, {}, 'SELECT foo FROM bar'); | ||
|
||
t.true(result === null); | ||
}); | ||
|
||
test('throws an error if more than one row is returned', async (t) => { | ||
const stub = sinon.stub().returns({ | ||
rows: [ | ||
{ | ||
foo: 1 | ||
}, | ||
{ | ||
foo: 2 | ||
} | ||
] | ||
}); | ||
|
||
const connection: any = { | ||
query: stub | ||
}; | ||
|
||
await t.throws(maybeOneFirst(connection, {}, 'SELECT foo FROM bar'), DataIntegrityError); | ||
}); |
Oops, something went wrong.