forked from Manuel1234477/Stellar-Micro-Donation-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrewrite-tests.js
More file actions
39 lines (32 loc) · 1.5 KB
/
rewrite-tests.js
File metadata and controls
39 lines (32 loc) · 1.5 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
const fs = require('fs');
const path = require('path');
const glob = require('glob');
// We use glob inside node to find all test files
const testFiles = glob.sync('tests/**/*.test.js', { cwd: __dirname });
testFiles.forEach(file => {
const fullPath = path.join(__dirname, file);
let content = fs.readFileSync(fullPath, 'utf8');
// Replace .get('/wallets'), .post('/donations'), etc. with /api/v1 prefix
let newContent = content.replace(/\.(get|post|put|patch|delete)\('\/(wallets|donations|stats|stream|transactions|api-keys)([^']*)'/g,
(match, method, route, rest) => {
return `.${method}('/api/v1/${route}${rest}'`;
}
);
// Also replace double quotes
newContent = newContent.replace(/\.(get|post|put|patch|delete)\("\/(wallets|donations|stats|stream|transactions|api-keys)([^"]*)"/g,
(match, method, route, rest) => {
return `.${method}("/api/v1/${route}${rest}"`;
}
);
// Replace template literals without expressions inside simple paths
newContent = newContent.replace(/\.(get|post|put|patch|delete)\(`\/(wallets|donations|stats|stream|transactions|api-keys)([^`]*?)`/g,
(match, method, route, rest) => {
return `.${method}(\`/api/v1/${route}${rest}\``;
}
);
// Requesting directly via supertest wrapped paths like request(app).post('/wallets')
if (content !== newContent) {
fs.writeFileSync(fullPath, newContent, 'utf8');
console.log(`Updated ${file}`);
}
});