-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathpostgresql.timestamp.test.js
More file actions
95 lines (87 loc) · 2.45 KB
/
postgresql.timestamp.test.js
File metadata and controls
95 lines (87 loc) · 2.45 KB
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
// Copyright IBM Corp. 2018,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';
const should = require('should');
let db, PostWithTimestamps;
describe('Timestamps', function() {
describe('type and precision', function() {
before(function() {
db = global.getDataSource();
PostWithTimestamps = db.define('PostWithTimestamps', {
timestampDefault: {
type: 'Date',
postgresql: {
dbDefault: 'now()',
},
},
timestampWithType: {
type: 'Date',
postgresql: {
dataType: 'TIMESTAMP WITH TIME ZONE',
dbDefault: 'now()',
},
},
timestampWithTypeNoZone: {
type: 'Date',
postgresql: {
dataType: 'TIMESTAMP WITHOUT TIME ZONE',
dbDefault: 'now()',
},
},
timestampWithPrecision: {
type: 'Date',
postgresql: {
dataType: 'TIMESTAMP WITH TIME ZONE',
dataPrecision: 3,
dbDefault: 'now()',
},
},
timestampFromJs: {
type: 'Date',
postgresql: {
dataType: 'TIMESTAMP WITH TIME ZONE',
dataPrecision: 3,
},
},
});
});
it('should run migration', function(done) {
db.automigrate('PostWithTimestamps', function() {
done();
});
});
it('create instance', function(done) {
PostWithTimestamps.create(
{
timestampDefault: new Date,
timestampWithType: new Date,
timestampWithTypeNoZone: new Date,
timestampWithPrecision: new Date,
timestampFromJs: new Date,
}, function(err, p) {
should.not.exist(err);
should.exist(p);
done();
},
);
});
it('should handle default value on creation', function(done) {
PostWithTimestamps.create(
{timestampWithTypeNoZone: new Date()}, function(err, p) {
should.not.exist(err);
should.exist(p);
done();
},
);
});
it('isActual() should return true', function(done) {
db.isActual(['PostWithTimestamps'], function(err, ok) {
if (err) return done(err);
ok.should.equal(true);
done();
});
});
});
});