-
Notifications
You must be signed in to change notification settings - Fork 30
/
oracle.regexp.test.js
111 lines (96 loc) · 2.9 KB
/
oracle.regexp.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright IBM Corp. 2017,2019. All Rights Reserved.
// Node module: loopback-connector-oracle
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
/* global getDataSource */
const async = require('async');
require('./init/init');
const should = require('should');
let db, User;
describe('regexp', function() {
db = getDataSource();
const User = db.define('UserRegExp', {
seq: {type: Number, index: true},
name: {type: String, index: true, sort: true},
email: {type: String, index: true},
});
before(seed);
it('should work when a regex is provided without the regexp operator',
function(done) {
User.find({where: {name: /John.*/i}}, function(err, users) {
should.not.exist(err);
users.length.should.equal(1);
users[0].name.should.equal('John Lennon');
done();
});
});
it('should work when a regex is case insensitive',
function(done) {
User.find({where: {name: /JOHN.*/i}}, function(err, users) {
should.not.exist(err);
users.length.should.equal(1);
users[0].name.should.equal('John Lennon');
done();
});
});
it('should work when a regex is case sensitive',
function(done) {
User.find({where: {name: /JOHN.*/}}, function(err, users) {
should.not.exist(err);
users.length.should.equal(0);
done();
});
});
it('should support the regexp operator with regex strings', function(done) {
User.find({where: {name: {regexp: '^J'}}}, function(err, users) {
should.not.exist(err);
users.length.should.equal(1);
users[0].name.should.equal('John Lennon');
done();
});
});
it('should support the regexp operator with regex literals', function(done) {
User.find({where: {name: {regexp: /^J/}}}, function(err, users) {
should.not.exist(err);
users.length.should.equal(1);
users[0].name.should.equal('John Lennon');
done();
});
});
it('should support the regexp operator with regex objects', function(done) {
User.find({where: {name: {regexp: new RegExp(/^J/)}}}, function(err,
users) {
should.not.exist(err);
users.length.should.equal(1);
users[0].name.should.equal('John Lennon');
done();
});
});
function seed(done) {
const beatles = [
{
seq: 0,
name: 'John Lennon',
email: 'john@b3atl3s.co.uk',
},
{
seq: 1,
name: 'Paul McCartney',
email: 'paul@b3atl3s.co.uk',
},
{seq: 2, name: 'George Harrison'},
{seq: 3, name: 'Ringo Starr'},
{seq: 4, name: 'Pete Best'},
{seq: 5, name: 'Stuart Sutcliffe'},
];
async.series([
function(cb) {
db.automigrate('UserRegExp', cb);
},
function(cb) {
async.each(beatles, User.create.bind(User), cb);
},
], done);
}
});