1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | 'use strict';
|
8 |
|
9 |
|
10 | const should = require('./init.js');
|
11 |
|
12 | const Schema = require('../').Schema;
|
13 | const ModelBuilder = require('../').ModelBuilder;
|
14 |
|
15 | describe('JSON property', function() {
|
16 | let dataSource, Model;
|
17 |
|
18 | it('should be defined', function() {
|
19 | dataSource = getSchema();
|
20 | Model = dataSource.define('Model', {propertyName: ModelBuilder.JSON});
|
21 | const m = new Model;
|
22 | (new Boolean('propertyName' in m)).should.eql(true);
|
23 | should.not.exist(m.propertyName);
|
24 | });
|
25 |
|
26 | it('should accept JSON in constructor and return object', function() {
|
27 | const m = new Model({
|
28 | propertyName: '{"foo": "bar"}',
|
29 | });
|
30 | m.propertyName.should.be.an.Object;
|
31 | m.propertyName.foo.should.equal('bar');
|
32 | });
|
33 |
|
34 | it('should accept object in setter and return object', function() {
|
35 | const m = new Model;
|
36 | m.propertyName = {'foo': 'bar'};
|
37 | m.propertyName.should.be.an.Object;
|
38 | m.propertyName.foo.should.equal('bar');
|
39 | });
|
40 |
|
41 | it('should accept string in setter and return string', function() {
|
42 | const m = new Model;
|
43 | m.propertyName = '{"foo": "bar"}';
|
44 | m.propertyName.should.be.a.String;
|
45 | m.propertyName.should.equal('{"foo": "bar"}');
|
46 | });
|
47 | });
|