-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathpostgresql.encrypted.test.js
79 lines (73 loc) · 2.28 KB
/
postgresql.encrypted.test.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright IBM Corp. 2014,2019. All Rights Reserved.
// Node module: loopback-connector-postgresql
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0
'use strict';
process.env.NODE_ENV = 'test';
require('should');
const expect = require('chai').expect;
const async = require('async');
const chai = require('chai');
const chaiSubset = require('chai-subset');
chai.use(chaiSubset);
let db;
before(function() {
db = global.getSchema();
});
describe('Mapping models', function() {
it('should return encrypted data by filter', function(done) {
const schema =
{
'name': 'EncryptedData',
'options': {
'idInjection': false,
'postgresql': {
'schema': 'public', 'table': 'encrypted_data',
},
},
'properties': {
'id': {
'type': 'String',
'id': true,
},
'data': {
'type': 'String',
},
},
'mixins': {
'Encryption': {
'fields': [
'data',
],
},
},
};
const EncryptedData = db.createModel(schema.name, schema.properties, schema.options);
EncryptedData.settings.mixins = schema.mixins;
db.automigrate('EncryptedData', function(err) {
if (err) console.error({err});
EncryptedData.create({
id: '2',
data: '1c93722e6cf53f93dd4eb15a18444dc3e910fded18239db612794059af1fa5e8',
}, function(err, encryptedData) {
if (err) console.log({err2: err});
async.series([
function(callback) {
EncryptedData.findOne({where: {data: {ilike: '%test%'}}}, function(err, retreivedData) {
if (err) console.error({err111: err});
expect(retreivedData).to.containSubset(encryptedData);
callback(null, retreivedData);
});
},
function(callback) {
EncryptedData.find({where: {data: {ilike: '%not found%'}}}, function(err, retreivedData) {
if (err) console.error({err111: err});
expect(retreivedData.length).to.equal(0);
callback(null, retreivedData);
});
},
], done);
});
});
});
});