File tree Expand file tree Collapse file tree 3 files changed +80
-0
lines changed
test/integration/controllers Expand file tree Collapse file tree 3 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * JsonController
3+ *
4+ * @description :: Server-side logic for managing jsons
5+ * @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
6+ */
7+
8+ module . exports = {
9+
10+ } ;
11+
Original file line number Diff line number Diff line change 1+ /**
2+ * Json.js
3+ *
4+ * @description :: TODO: You might write a short summary of how this model works and what it represents here.
5+ * @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models
6+ */
7+
8+ module . exports = {
9+
10+ attributes : {
11+ variable : {
12+ type : 'string'
13+ } ,
14+ invisible : {
15+ type : 'string'
16+ } ,
17+
18+ toJSON : function ( ) {
19+
20+ var obj = this . toObject ( ) ;
21+ delete obj . invisible ;
22+
23+ return obj ;
24+ }
25+ } ,
26+
27+ autoCreatedAt : false ,
28+ autoUpdatedAt : false
29+ } ;
Original file line number Diff line number Diff line change 1+ var request = require ( 'supertest' ) ;
2+ var JSONAPIValidator = require ( 'jsonapi-validator' ) . Validator ;
3+
4+ validateJSONapi = function ( res ) {
5+ var validator = new JSONAPIValidator ( ) ;
6+
7+ validator . validate ( res . body ) ;
8+ } ;
9+
10+ describe ( 'toJSON compatibility' , function ( ) {
11+
12+ it ( 'Should return record without the hidden field' , function ( done ) {
13+
14+ let toCreate = {
15+ 'data' : {
16+ 'attributes' : {
17+ variable : "test" ,
18+ invisible : "should not be displayed"
19+ } ,
20+ 'type' : 'jsons'
21+ }
22+ } ;
23+
24+ request ( sails . hooks . http . app )
25+ . post ( '/jsons' )
26+ . send ( toCreate )
27+ . expect ( 201 )
28+ . expect ( validateJSONapi )
29+ . expect ( {
30+ data : {
31+ id : '1' ,
32+ type : 'jsons' ,
33+ attributes : {
34+ variable : 'test'
35+ }
36+ }
37+ } )
38+ . end ( done ) ;
39+ } ) ;
40+ } ) ;
You can’t perform that action at this time.
0 commit comments