-
Notifications
You must be signed in to change notification settings - Fork 73k
Expand file tree
/
Copy path00_production-safety.test.js
More file actions
61 lines (54 loc) · 1.96 KB
/
00_production-safety.test.js
File metadata and controls
61 lines (54 loc) · 1.96 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
'use strict';
/**
* Production Safety Check - Database Level
*
* GAP-SYNC-047: This test runs FIRST (00_ prefix) to verify
* the database is safe for destructive test operations.
*
* Checks:
* 1. Database name contains "test"
* 2. Entry count is below threshold (default: 100)
*
* Environment Variables:
* - TEST_SAFETY_MAX_ENTRIES: Max entries before refusing (default: 100)
* - TEST_SAFETY_REQUIRE_TEST_DB: Require "test" in DB name (default: true)
* - TEST_SAFETY_SKIP: Bypass all checks (dangerous!)
*/
var should = require('should');
var language = require('../lib/language')();
var productionSafety = require('./lib/production-safety');
describe('00 Production Safety Check', function() {
this.timeout(10000);
var self = this;
before(function(done) {
// Boot the app to get DB connection
process.env.API_SECRET = 'this is my long pass phrase';
self.env = require('../lib/server/env')();
self.env.settings.authDefaultRoles = 'readable';
self.env.settings.enable = ['careportal', 'api'];
require('../lib/server/bootevent')(self.env, language).boot(function booted(ctx) {
self.ctx = ctx;
done();
});
});
it('should verify database is safe for destructive tests', function(done) {
// This is the critical safety gate
productionSafety.checkProductionSafety(self.ctx, self.env)
.then(function() {
done();
})
.catch(function(err) {
// Fail the test suite immediately
console.error('\n\n' + '!'.repeat(70));
console.error('TEST SUITE HALTED - Production safety check activated');
console.error('!'.repeat(70) + '\n');
process.exit(1);
});
});
it('should have extracted correct database name', function() {
var dbName = productionSafety.extractDbName(self.env.storageURI || self.env.mongo_connection || '');
dbName.should.be.a.String();
dbName.length.should.be.greaterThan(0);
console.log('[SAFETY] Database name: ' + dbName);
});
});