@@ -4,7 +4,7 @@ import { expect } from 'chai';
44import assert from 'assert' ;
55import feathers from 'feathers' ;
66import knex from 'knex' ;
7- import { base , orm , example } from 'feathers-service-tests' ;
7+ import { base , example } from 'feathers-service-tests' ;
88import { errors } from 'feathers-errors' ;
99import service from '../src' ;
1010import server from '../example/app' ;
@@ -16,92 +16,74 @@ const db = knex({
1616 }
1717} ) ;
1818
19- const app = feathers ( ) . use ( '/people' , service ( {
20- Model : db ,
21- name : 'people'
22- } ) ) ;
23-
24- let _ids = { } ;
25- let people = app . service ( 'people' ) ;
26-
27- function clean ( done ) {
28- db . schema . dropTableIfExists ( 'people' ) . then ( ( ) => {
29- db . schema . createTable ( 'people' , table => {
30- table . increments ( 'id' ) ;
31- table . string ( 'name' ) ;
32- table . integer ( 'age' ) ;
33- table . integer ( 'time' ) ;
34- table . boolean ( 'created' ) ;
35- } )
36- . then ( ( ) => {
37- done ( ) ;
38- } ) ;
39- } ) ;
19+ function clean ( ) {
20+ return db . schema . dropTableIfExists ( 'people' )
21+ . then ( ( ) => db . schema . dropTableIfExists ( 'people-customid' ) )
22+ . then ( ( ) =>
23+ db . schema . createTable ( 'people' , table => {
24+ table . increments ( 'id' ) ;
25+ table . string ( 'name' ) ;
26+ table . integer ( 'age' ) ;
27+ table . integer ( 'time' ) ;
28+ table . boolean ( 'created' ) ;
29+ } ) . then ( ( ) => db . schema . createTable ( 'people-customid' , table => {
30+ table . increments ( 'customid' ) ;
31+ table . string ( 'name' ) ;
32+ table . integer ( 'age' ) ;
33+ table . integer ( 'time' ) ;
34+ table . boolean ( 'created' ) ;
35+ } ) )
36+ ) ;
4037}
4138
4239describe ( 'Feathers Knex Service' , ( ) => {
40+ const app = feathers ( ) . use ( '/people' , service ( {
41+ Model : db ,
42+ name : 'people' ,
43+ events : [ 'testing' ]
44+ } ) ) . use ( '/people-customid' , service ( {
45+ Model : db ,
46+ id : 'customid' ,
47+ name : 'people-customid' ,
48+ events : [ 'testing' ]
49+ } ) ) ;
50+
4351 before ( clean ) ;
4452 after ( clean ) ;
4553
4654 describe ( 'Initialization' , ( ) => {
4755 describe ( 'when missing options' , ( ) => {
48- it ( 'throws an error' , ( ) => {
49- expect ( service . bind ( null ) ) . to . throw ( 'Knex options have to be provided' ) ;
50- } ) ;
56+ it ( 'throws an error' , ( ) =>
57+ expect ( service . bind ( null ) )
58+ . to . throw ( 'Knex options have to be provided' )
59+ ) ;
5160 } ) ;
5261
5362 describe ( 'when missing a Model' , ( ) => {
54- it ( 'throws an error' , ( ) => {
55- expect ( service . bind ( null , { } ) ) . to . throw ( / Y o u m u s t p r o v i d e a M o d e l / ) ;
56- } ) ;
63+ it ( 'throws an error' , ( ) =>
64+ expect ( service . bind ( null , { } ) )
65+ . to . throw ( / Y o u m u s t p r o v i d e a M o d e l / )
66+ ) ;
5767 } ) ;
5868
5969 describe ( 'when missing a table name' , ( ) => {
60- it ( 'throws an error' , ( ) => {
61- expect ( service . bind ( null , { Model : { } } ) ) . to . throw ( 'No table name specified.' ) ;
62- } ) ;
63- } ) ;
64-
65- describe ( 'when missing the id option' , ( ) => {
66- it ( 'sets the default to be id' , ( ) => {
67- expect ( people . id ) . to . equal ( 'id' ) ;
68- } ) ;
69- } ) ;
70-
71- describe ( 'when missing the paginate option' , ( ) => {
72- it ( 'sets the default to be {}' , ( ) => {
73- expect ( people . paginate ) . to . deep . equal ( { } ) ;
74- } ) ;
70+ it ( 'throws an error' , ( ) =>
71+ expect ( service . bind ( null , { Model : { } } ) )
72+ . to . throw ( 'No table name specified.' )
73+ ) ;
7574 } ) ;
7675 } ) ;
7776
7877 describe ( 'Common functionality' , ( ) => {
79- beforeEach ( done => {
80- people . create ( {
81- name : 'Doug' ,
82- age : 32
83- } ) . then ( data => {
84- _ids . Doug = data . id ;
85- done ( ) ;
86- } , done ) ;
87- } ) ;
88-
89- afterEach ( done => {
90- people . remove ( _ids . Doug , { } ) . then ( ( ) => done ( ) , ( ) => done ( ) ) ;
91- } ) ;
78+ it ( 'is CommonJS compatible' , ( ) =>
79+ assert . equal ( typeof require ( '../lib' ) , 'function' )
80+ ) ;
9281
93- it ( 'is CommonJS compatible' , ( ) => {
94- assert . equal ( typeof require ( '../lib' ) , 'function' ) ;
95- } ) ;
96-
97- base ( people , _ids , errors ) ;
82+ base ( app , errors , 'people' ) ;
83+ base ( app , errors , 'people-customid' , 'customid' ) ;
9884 } ) ;
9985} ) ;
10086
101- describe . skip ( 'Knex service ORM errors' , ( ) => {
102- orm ( people , _ids , errors ) ;
103- } ) ;
104-
10587describe ( 'Knex service example test' , ( ) => {
10688 after ( done => server . close ( ( ) => done ( ) ) ) ;
10789
0 commit comments