-
-
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.
- Loading branch information
Showing
5 changed files
with
205 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @flow | ||
|
||
/* eslint-disable flowtype/no-weak-types */ | ||
|
||
import test from 'ava'; | ||
import sinon from 'sinon'; | ||
import { | ||
anyFirst, | ||
DataIntegrityError | ||
} from '../../src'; | ||
|
||
test('returns values of the query result rows', async (t) => { | ||
const stub = sinon.stub().returns({ | ||
rows: [ | ||
{ | ||
foo: 1 | ||
}, | ||
{ | ||
foo: 2 | ||
} | ||
] | ||
}); | ||
|
||
const connection: any = { | ||
query: stub | ||
}; | ||
|
||
const result = await anyFirst(connection, {}, ''); | ||
|
||
t.deepEqual(result, [ | ||
1, | ||
2 | ||
]); | ||
}); | ||
|
||
test('throws an error if more than one column is returned', async (t) => { | ||
const stub = sinon.stub().returns({ | ||
rows: [ | ||
{ | ||
bar: 1, | ||
foo: 1 | ||
} | ||
] | ||
}); | ||
|
||
const connection: any = { | ||
query: stub | ||
}; | ||
|
||
await t.throws(anyFirst(connection, {}, ''), DataIntegrityError); | ||
}); |
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,51 @@ | ||
// @flow | ||
|
||
/* eslint-disable flowtype/no-weak-types */ | ||
|
||
import test from 'ava'; | ||
import sinon from 'sinon'; | ||
import { | ||
DataIntegrityError, | ||
manyFirst | ||
} from '../../src'; | ||
|
||
test('returns values of the query result rows', async (t) => { | ||
const stub = sinon.stub().returns({ | ||
rows: [ | ||
{ | ||
foo: 1 | ||
}, | ||
{ | ||
foo: 2 | ||
} | ||
] | ||
}); | ||
|
||
const connection: any = { | ||
query: stub | ||
}; | ||
|
||
const result = await manyFirst(connection, {}, ''); | ||
|
||
t.deepEqual(result, [ | ||
1, | ||
2 | ||
]); | ||
}); | ||
|
||
test('throws an error if more than one column is returned', async (t) => { | ||
const stub = sinon.stub().returns({ | ||
rows: [ | ||
{ | ||
bar: 1, | ||
foo: 1 | ||
} | ||
] | ||
}); | ||
|
||
const connection: any = { | ||
query: stub | ||
}; | ||
|
||
await t.throws(manyFirst(connection, {}, ''), DataIntegrityError); | ||
}); |