Skip to content

Commit 053240c

Browse files
committed
Test should work even if Model's primary key is not id
1 parent ffb73e7 commit 053240c

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* CustomController
3+
*
4+
* @description :: Server-side logic for managing customs
5+
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
6+
*/
7+
8+
module.exports = {
9+
10+
};
11+

tests/dummy/api/models/Custom.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Custom.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+
autoPK: false,
11+
12+
attributes: {
13+
key: {
14+
type: 'integer',
15+
autoIncrement: true,
16+
primaryKey: true,
17+
unique: true,
18+
index: true
19+
}
20+
},
21+
22+
autoCreatedAt: false,
23+
autoUpdatedAt: false
24+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var clone = require('clone');
2+
var request = require('supertest');
3+
var JSONAPIValidator = require('jsonapi-validator').Validator;
4+
5+
validateJSONapi = function(res) {
6+
var validator = new JSONAPIValidator();
7+
8+
validator.validate(res.body);
9+
};
10+
11+
describe("Custom primary key name", function() {
12+
13+
describe("POST /customs", function() {
14+
15+
it('Should return a unique identifier from custom sails primaryKey', function (done) {
16+
17+
var categoryToCreate = {
18+
'data': {
19+
'attributes': {
20+
},
21+
'type':'customs'
22+
}
23+
};
24+
25+
categoryCreated = clone(categoryToCreate);
26+
categoryCreated.data.id = "1";
27+
28+
request(sails.hooks.http.app)
29+
.post('/customs')
30+
.send(categoryToCreate)
31+
.expect(201)
32+
.expect(validateJSONapi)
33+
.expect(categoryCreated)
34+
.end(done);
35+
});
36+
});
37+
});

0 commit comments

Comments
 (0)