1- import { createStore } from '../dev/' ;
1+ import {
2+ createStore
3+ } from '../dev/' ;
24import User from '../dev/common/models/User' ;
35import Role from '../dev/common/models/Role' ;
4- import { expect } from 'chai' ;
5-
6- describe ( 'Vuex ORM $isDirty/$isNew plugin default installation' , function ( ) {
7- it ( 'should have both flag set to false when creating new' , function ( ) {
8- const store = createStore ( [ { model : User } ] ) ;
6+ import {
7+ expect
8+ } from 'chai' ;
9+
10+ describe ( 'Vuex ORM $isDirty/$isNew plugin default installation' , function ( ) {
11+ it ( 'should have both flag set to false when creating new' , function ( ) {
12+ const store = createStore ( [ {
13+ model : User
14+ } ] ) ;
915 let u = new User ( ) ;
1016 expect ( u . $isDirty ) . to . equal ( false ) ;
1117 expect ( u . $isNew ) . to . equal ( false ) ;
1218 } ) ;
1319
14- it ( 'should have both flags set to true when creating using the createNew method -- No store insertion' , function ( ) {
15- const store = createStore ( [ { model : User } ] ) ;
16- let u = User . createNew ( false ) ;
20+ it ( 'should have both flags set to true when creating using the createNew method -- No store insertion' , async function ( ) {
21+ const store = createStore ( [ {
22+ model : User
23+ } ] ) ;
24+ let u = await User . createNew ( false ) ;
1725 expect ( u . $isDirty ) . to . equal ( true ) ;
1826 expect ( u . $isNew ) . to . equal ( true ) ;
1927 } ) ;
2028
21- it ( 'should have both flags set to true when creating using the createNew method -- With store insertion' , function ( ) {
22- const store = createStore ( [ { model : User } ] ) ;
23- User . createNew ( ) ;
29+ it ( 'should have both flags set to true when creating using the createNew method -- With store insertion' , async function ( ) {
30+ const store = createStore ( [ {
31+ model : User
32+ } ] ) ;
33+ let u1 = await User . createNew ( ) ;
2434
25- let u = store . getters [ 'entities/users/all' ] ( ) [ 0 ] ;
26- expect ( u . $isDirty ) . to . equal ( true ) ;
27- expect ( u . $isNew ) . to . equal ( true ) ;
35+ let u2 = store . getters [ 'entities/users/all' ] ( ) [ 0 ] ;
36+ expect ( u2 . $isDirty ) . to . equal ( true ) ;
37+ expect ( u2 . $isNew ) . to . equal ( true ) ;
38+ expect ( u1 . id ) . to . equal ( u2 . id ) ;
2839 } ) ;
2940
30- it ( 'should take record flags when instanciating from existing' , function ( ) {
31- const store = createStore ( [ { model : User } ] ) ;
41+ it ( 'should take record flags when instanciating from existing' , function ( ) {
42+ const store = createStore ( [ {
43+ model : User
44+ } ] ) ;
3245 let user = {
3346 name : 'A' ,
3447 email : 'B' ,
@@ -41,42 +54,70 @@ describe('Vuex ORM $isDirty/$isNew plugin default installation', function() {
4154 expect ( u . $isNew ) . to . equal ( false ) ;
4255 } ) ;
4356
44- it ( 'should set $isDirty flag to true when updating data in store' , function ( ) {
45- const store = createStore ( [ { model : User } ] ) ;
57+ it ( 'should set $isDirty flag to true when updating data in store' , function ( ) {
58+ const store = createStore ( [ {
59+ model : User
60+ } ] ) ;
4661
4762 // Creating using the constructor, not the factory
4863 // to make sure $isDirty / $isNew are false
49- let user = new User ( { id : 1 } ) ;
64+ let user = new User ( {
65+ id : 1
66+ } ) ;
5067
5168 // Inserting new data
52- User . insert ( { data : user } ) ;
69+ User . insert ( {
70+ data : user
71+ } ) ;
5372 expect ( user . $isDirty ) . to . equal ( false ) ;
5473
5574 // Updating
5675 user . email = 'AA' ;
57- User . update ( { data : user } ) ;
76+ User . update ( {
77+ data : user
78+ } ) ;
5879
5980 // Checking
6081 let result = store . getters [ 'entities/users/find' ] ( 1 ) ;
6182
6283 expect ( result . $isDirty ) . to . equal ( true ) ;
6384 } ) ;
6485
65- it ( 'should provide a way to fetch all dirty entities in one call' , function ( ) {
66- const store = createStore ( [ { model : User } , { model : Role } ] ) ;
86+ it ( 'should provide a way to fetch all dirty entities in one call' , function ( ) {
87+ const store = createStore ( [ {
88+ model : User
89+ } , {
90+ model : Role
91+ } ] ) ;
6792
68- let user = new User ( { id : 1 , roleId : 1 } ) ;
69- let user2 = new User ( { id : 2 , roleId : 1 } ) ;
70- let role = new Role ( { id : 3 } ) ;
93+ let user = new User ( {
94+ id : 1 ,
95+ roleId : 1
96+ } ) ;
97+ let user2 = new User ( {
98+ id : 2 ,
99+ roleId : 1
100+ } ) ;
101+ let role = new Role ( {
102+ id : 3
103+ } ) ;
71104
72- User . insert ( { data : [ user , user2 ] } ) ;
73- Role . insert ( { data : role } ) ;
105+ User . insert ( {
106+ data : [ user , user2 ]
107+ } ) ;
108+ Role . insert ( {
109+ data : role
110+ } ) ;
74111
75112 user . name = 'AA' ;
76113 role . name = 'AA' ;
77114
78- User . update ( { data : user } ) ;
79- Role . update ( { data : role } ) ;
115+ User . update ( {
116+ data : user
117+ } ) ;
118+ Role . update ( {
119+ data : role
120+ } ) ;
80121
81122 let result = store . getters [ 'entities/allDirty' ] ( ) ;
82123 expect ( result . length ) . to . equal ( 2 ) ;
@@ -89,32 +130,59 @@ describe('Vuex ORM $isDirty/$isNew plugin default installation', function() {
89130 expect ( result [ 1 ] . id ) . to . equal ( 3 ) ;
90131 } ) ;
91132
92- it ( 'should provide a way to fetch all dirty entities of one type' , function ( ) {
93- const store = createStore ( [ { model : User } , { model : Role } ] ) ;
133+ it ( 'should provide a way to fetch all dirty entities of one type' , function ( ) {
134+ const store = createStore ( [ {
135+ model : User
136+ } , {
137+ model : Role
138+ } ] ) ;
94139
95- let user = new User ( { id : 1 , roleId : 1 } ) ;
96- let user2 = new User ( { id : 2 , roleId : 1 } ) ;
97- let role = new Role ( { id : 3 } ) ;
140+ let user = new User ( {
141+ id : 1 ,
142+ roleId : 1
143+ } ) ;
144+ let user2 = new User ( {
145+ id : 2 ,
146+ roleId : 1
147+ } ) ;
148+ let role = new Role ( {
149+ id : 3
150+ } ) ;
98151
99- User . insert ( { data : [ user , user2 ] } ) ;
100- Role . insert ( { data : role } ) ;
152+ User . insert ( {
153+ data : [ user , user2 ]
154+ } ) ;
155+ Role . insert ( {
156+ data : role
157+ } ) ;
101158
102159 user . name = 'AA' ;
103160 role . name = 'AA' ;
104161
105- User . update ( { data : user } ) ;
106- Role . update ( { data : role } ) ;
162+ User . update ( {
163+ data : user
164+ } ) ;
165+ Role . update ( {
166+ data : role
167+ } ) ;
107168
108169 let result = store . getters [ 'entities/users/allDirty' ] ( ) ;
109170 expect ( result . length ) . to . equal ( 1 ) ;
110171 expect ( result [ 0 ] . id ) . to . equal ( 1 ) ;
111172 } ) ;
112173
113- it ( 'should provide a way to fetch all new entities in one call' , function ( ) {
114- const store = createStore ( [ { model : User } , { model : Role } ] ) ;
174+ it ( 'should provide a way to fetch all new entities in one call' , function ( ) {
175+ const store = createStore ( [ {
176+ model : User
177+ } , {
178+ model : Role
179+ } ] ) ;
115180
116181 let user = User . createNew ( ) ;
117- let user2 = new User ( { id : 2 , roleId : 1 } ) ;
182+ let user2 = new User ( {
183+ id : 2 ,
184+ roleId : 1
185+ } ) ;
118186 let role = Role . createNew ( ) ;
119187
120188 let result = store . getters [ 'entities/allNew' ] ( ) ;
@@ -124,16 +192,23 @@ describe('Vuex ORM $isDirty/$isNew plugin default installation', function() {
124192 expect ( result [ 1 ] . id ) . to . equal ( 1 ) ;
125193 } ) ;
126194
127- it ( 'should provide a way to fetch new entities of one type' , function ( ) {
128- const store = createStore ( [ { model : User } , { model : Role } ] ) ;
195+ it ( 'should provide a way to fetch new entities of one type' , function ( ) {
196+ const store = createStore ( [ {
197+ model : User
198+ } , {
199+ model : Role
200+ } ] ) ;
129201
130202 let user = User . createNew ( ) ;
131- let user2 = new User ( { id : 2 , roleId : 1 } ) ;
203+ let user2 = new User ( {
204+ id : 2 ,
205+ roleId : 1
206+ } ) ;
132207 let role = Role . createNew ( ) ;
133208
134209 let result = store . getters [ 'entities/users/allNew' ] ( ) ;
135210 expect ( result . length ) . to . equal ( 1 ) ;
136211
137212 expect ( result [ 0 ] instanceof User ) . to . equal ( true ) ;
138213 } ) ;
139- } ) ;
214+ } ) ;
0 commit comments