-
Notifications
You must be signed in to change notification settings - Fork 73k
Expand file tree
/
Copy pathproduction-safety.test.js
More file actions
88 lines (68 loc) · 3.1 KB
/
production-safety.test.js
File metadata and controls
88 lines (68 loc) · 3.1 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
'use strict';
/**
* Unit tests for production-safety.js module
*/
var should = require('should');
var productionSafety = require('./lib/production-safety');
describe('Production Safety Module', function() {
describe('extractDbName', function() {
it('should extract database name from standard MongoDB URI', function() {
var dbName = productionSafety.extractDbName('mongodb://localhost:27017/nightscout_test');
dbName.should.equal('nightscout_test');
});
it('should extract database name from MongoDB+SRV URI', function() {
var dbName = productionSafety.extractDbName('mongodb+srv://user:pass@cluster.mongodb.net/mydb_test');
dbName.should.equal('mydb_test');
});
it('should handle URI with query parameters', function() {
var dbName = productionSafety.extractDbName('mongodb://localhost:27017/nightscout_test?retryWrites=true');
dbName.should.equal('nightscout_test');
});
it('should handle URI with auth credentials', function() {
var dbName = productionSafety.extractDbName('mongodb://user:password@localhost:27017/test_db');
dbName.should.equal('test_db');
});
it('should return default for empty connection string', function() {
var dbName = productionSafety.extractDbName('');
dbName.should.be.a.String();
});
});
describe('isTestDatabaseName', function() {
it('should recognize "_test" suffix', function() {
productionSafety.isTestDatabaseName('nightscout_test').should.be.true();
});
it('should recognize "test_" prefix', function() {
productionSafety.isTestDatabaseName('test_nightscout').should.be.true();
});
it('should recognize "test" anywhere in name', function() {
productionSafety.isTestDatabaseName('my_testing_db').should.be.true();
});
it('should be case insensitive', function() {
productionSafety.isTestDatabaseName('Nightscout_TEST').should.be.true();
productionSafety.isTestDatabaseName('TEST_DB').should.be.true();
});
it('should reject production-looking names', function() {
productionSafety.isTestDatabaseName('nightscout').should.be.false();
productionSafety.isTestDatabaseName('production').should.be.false();
productionSafety.isTestDatabaseName('mydb').should.be.false();
});
it('should reject names with "test" as substring of other words', function() {
// "contest" contains "test" but is not a test database
// Current implementation will actually match this - documenting behavior
productionSafety.isTestDatabaseName('contest').should.be.true(); // Contains "test"
});
});
describe('DEFAULT_MAX_ENTRIES', function() {
it('should be a reasonable default (100)', function() {
productionSafety.DEFAULT_MAX_ENTRIES.should.equal(100);
});
});
describe('preflightCheck', function() {
it('should not throw when NODE_ENV=test', function() {
// This test is running, so NODE_ENV must be test
process.env.NODE_ENV.should.equal('test');
// preflightCheck would have already run via hooks.js
// If we got here, it passed
});
});
});