-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2461 from marmelab/export-one-to-many
[RFR] Add support for arrays of references in fetchRelatedRecords
- Loading branch information
Showing
2 changed files
with
63 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getRelatedIds } from './ExportButton'; | ||
|
||
describe('ExportButton', () => { | ||
describe('getRelatedIds', () => { | ||
it('should ignore null or undefined values', () => { | ||
const books = [ | ||
{ id: 1, author_id: 123, title: 'Pride and Prejudice' }, | ||
{ id: 2, author_id: null }, | ||
{ id: 3 }, | ||
]; | ||
expect(getRelatedIds(books, 'author_id')).toEqual([123]); | ||
}); | ||
it('should aggregate scalar related ids', () => { | ||
const books = [ | ||
{ id: 1, author_id: 123, title: 'Pride and Prejudice' }, | ||
{ id: 2, author_id: 123, title: 'Sense and Sensibility' }, | ||
{ id: 3, author_id: 456, title: 'War and Peace' }, | ||
]; | ||
expect(getRelatedIds(books, 'author_id')).toEqual([123, 456]); | ||
}); | ||
it('should aggregate arrays of related ids', () => { | ||
const books = [ | ||
{ id: 1, tag_ids: [1, 2], title: 'Pride and Prejudice' }, | ||
{ id: 2, tag_ids: [2, 3], title: 'Sense and Sensibility' }, | ||
{ id: 3, tag_ids: [4], title: 'War and Peace' }, | ||
]; | ||
expect(getRelatedIds(books, 'tag_ids')).toEqual([1, 2, 3, 4]); | ||
}); | ||
}); | ||
}); |