UNPKG

1.45 kBJavaScriptView Raw
1// Copyright IBM Corp. 2013,2019. All Rights Reserved.
2// Node module: loopback-datasource-juggler
3// This file is licensed under the MIT License.
4// License text available at https://opensource.org/licenses/MIT
5
6// This test written in mocha+should.js
7'use strict';
8
9/* global getSchema:false */
10const should = require('./init.js');
11
12const Schema = require('../').Schema;
13const ModelBuilder = require('../').ModelBuilder;
14
15describe('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});