2016-04-06 14:51:49 +00:00
|
|
|
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
|
|
|
|
// Node module: loopback-datasource-juggler
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
2016-10-19 21:35:26 +00:00
|
|
|
'use strict';
|
2016-04-06 14:51:49 +00:00
|
|
|
|
2013-04-06 10:57:12 +00:00
|
|
|
// This test written in mocha+should.js
|
|
|
|
var should = require('./init.js');
|
|
|
|
|
2013-03-24 22:29:13 +00:00
|
|
|
var Schema = require('../').Schema;
|
2013-11-09 01:13:00 +00:00
|
|
|
var ModelBuilder = require('../').ModelBuilder;
|
2013-03-19 10:05:38 +00:00
|
|
|
|
2016-04-14 14:41:19 +00:00
|
|
|
describe('JSON property', function() {
|
2014-01-24 17:09:53 +00:00
|
|
|
var dataSource, Model;
|
2013-03-19 10:05:38 +00:00
|
|
|
|
2016-04-14 14:41:19 +00:00
|
|
|
it('should be defined', function() {
|
2014-01-24 17:09:53 +00:00
|
|
|
dataSource = getSchema();
|
2016-10-19 21:04:05 +00:00
|
|
|
Model = dataSource.define('Model', {propertyName: ModelBuilder.JSON});
|
2014-01-24 17:09:53 +00:00
|
|
|
var m = new Model;
|
|
|
|
(new Boolean('propertyName' in m)).should.eql(true);
|
|
|
|
should.not.exist(m.propertyName);
|
|
|
|
});
|
2013-03-19 10:05:38 +00:00
|
|
|
|
2016-04-14 14:41:19 +00:00
|
|
|
it('should accept JSON in constructor and return object', function() {
|
2014-01-24 17:09:53 +00:00
|
|
|
var m = new Model({
|
2016-04-14 14:41:19 +00:00
|
|
|
propertyName: '{"foo": "bar"}',
|
2013-03-19 10:05:38 +00:00
|
|
|
});
|
2014-01-24 17:09:53 +00:00
|
|
|
m.propertyName.should.be.an.Object;
|
|
|
|
m.propertyName.foo.should.equal('bar');
|
|
|
|
});
|
2013-03-19 10:05:38 +00:00
|
|
|
|
2016-04-14 14:41:19 +00:00
|
|
|
it('should accept object in setter and return object', function() {
|
2014-01-24 17:09:53 +00:00
|
|
|
var m = new Model;
|
2016-10-19 21:04:05 +00:00
|
|
|
m.propertyName = {'foo': 'bar'};
|
2014-01-24 17:09:53 +00:00
|
|
|
m.propertyName.should.be.an.Object;
|
|
|
|
m.propertyName.foo.should.equal('bar');
|
|
|
|
});
|
2013-03-19 10:05:38 +00:00
|
|
|
|
2016-04-14 14:41:19 +00:00
|
|
|
it('should accept string in setter and return string', function() {
|
2014-01-24 17:09:53 +00:00
|
|
|
var m = new Model;
|
|
|
|
m.propertyName = '{"foo": "bar"}';
|
|
|
|
m.propertyName.should.be.a.String;
|
|
|
|
m.propertyName.should.equal('{"foo": "bar"}');
|
|
|
|
});
|
2013-03-19 10:05:38 +00:00
|
|
|
});
|