Blame view

node_modules/loopback-datasource-juggler/test/json.test.js 1.38 KB
f7563de62   Palak Handa   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  // 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
  'use strict';
  
  // This test written in mocha+should.js
  var should = require('./init.js');
  
  var Schema = require('../').Schema;
  var ModelBuilder = require('../').ModelBuilder;
  
  describe('JSON property', function() {
    var dataSource, Model;
  
    it('should be defined', function() {
      dataSource = getSchema();
      Model = dataSource.define('Model', {propertyName: ModelBuilder.JSON});
      var m = new Model;
      (new Boolean('propertyName' in m)).should.eql(true);
      should.not.exist(m.propertyName);
    });
  
    it('should accept JSON in constructor and return object', function() {
      var m = new Model({
        propertyName: '{"foo": "bar"}',
      });
      m.propertyName.should.be.an.Object;
      m.propertyName.foo.should.equal('bar');
    });
  
    it('should accept object in setter and return object', function() {
      var m = new Model;
      m.propertyName = {'foo': 'bar'};
      m.propertyName.should.be.an.Object;
      m.propertyName.foo.should.equal('bar');
    });
  
    it('should accept string in setter and return string', function() {
      var m = new Model;
      m.propertyName = '{"foo": "bar"}';
      m.propertyName.should.be.a.String;
      m.propertyName.should.equal('{"foo": "bar"}');
    });
  });