|
| 1 | +import { splitModel } from './' |
| 2 | +import { kebab, snake } from '../' |
| 3 | +import plural from 'pluralize' |
| 4 | + |
| 5 | +describe('kitsu-core', () => { |
| 6 | + describe('splitModel', () => { |
| 7 | + it('anime -> anime', () => { |
| 8 | + expect.assertions(1) |
| 9 | + expect(splitModel('anime')) |
| 10 | + .toStrictEqual([ 'anime', 'anime' ]) |
| 11 | + }) |
| 12 | + |
| 13 | + it('anime -> anime (plural, mass noun)', () => { |
| 14 | + expect.assertions(1) |
| 15 | + expect(splitModel('anime', { |
| 16 | + pluralModel: plural |
| 17 | + })) |
| 18 | + .toStrictEqual([ 'anime', 'anime' ]) |
| 19 | + }) |
| 20 | + |
| 21 | + it('post -> post', () => { |
| 22 | + expect.assertions(1) |
| 23 | + expect(splitModel('post')) |
| 24 | + .toStrictEqual([ 'post', 'post' ]) |
| 25 | + }) |
| 26 | + |
| 27 | + it('post -> posts (plural)', () => { |
| 28 | + expect.assertions(1) |
| 29 | + expect(splitModel('post', { |
| 30 | + pluralModel: plural |
| 31 | + })) |
| 32 | + .toStrictEqual([ 'post', 'posts' ]) |
| 33 | + }) |
| 34 | + |
| 35 | + it('post/1/relationships/comment -> comment', () => { |
| 36 | + expect.assertions(1) |
| 37 | + expect(splitModel('post/1/relationships/comment')) |
| 38 | + .toStrictEqual([ 'comment', 'post/1/relationships/comment' ]) |
| 39 | + }) |
| 40 | + |
| 41 | + it('post/1/relationships/comment -> comment (plural)', () => { |
| 42 | + expect.assertions(1) |
| 43 | + expect(splitModel('post/1/relationships/comment', { |
| 44 | + pluralModel: plural |
| 45 | + })) |
| 46 | + .toStrictEqual([ 'comment', 'post/1/relationships/comments' ]) |
| 47 | + }) |
| 48 | + |
| 49 | + it('libraryEntry -> library-entry', () => { |
| 50 | + expect.assertions(1) |
| 51 | + expect(splitModel('libraryEntry', { |
| 52 | + resourceCase: kebab |
| 53 | + })) |
| 54 | + .toStrictEqual([ 'libraryEntry', 'library-entry' ]) |
| 55 | + }) |
| 56 | + |
| 57 | + it('libraryEntry -> library_entry', () => { |
| 58 | + expect.assertions(1) |
| 59 | + expect(splitModel('libraryEntry', { |
| 60 | + resourceCase: snake |
| 61 | + })) |
| 62 | + .toStrictEqual([ 'libraryEntry', 'library_entry' ]) |
| 63 | + }) |
| 64 | + }) |
| 65 | +}) |
0 commit comments