Skip to content

Commit a69698b

Browse files
UrognaMauro Quarta
andauthored
feat: rehash and custom hash (#187)
Co-authored-by: Mauro Quarta <mauro@smartive.ch>
1 parent e89ebbe commit a69698b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ route.get('/recordings', (_, res) => {
129129
res.send(recordingsContext.recordings);
130130
});
131131

132+
route.post('/recordings/rehash', (_req, res) => {
133+
console.log('Rehashing recordings');
134+
const newRecordings = {};
135+
136+
Object.values(recordingsContext.recordings)
137+
.flat()
138+
.forEach((recording) => {
139+
const hash = recording.request.headers['x-mock-hash'] || getShaFromData(recording.request);
140+
if (!newRecordings[hash]) {
141+
newRecordings[hash] = [];
142+
}
143+
newRecordings[hash].push(recording);
144+
});
145+
146+
recordingsContext.recordings = newRecordings;
147+
res.send(recordingsContext.recordings);
148+
});
149+
132150
route.get('/calls', (_req, res) => {
133151
res.send(calls);
134152
});
@@ -243,7 +261,7 @@ app.all('/*splat', async (req, res) => {
243261
delete dataToHash.headers[header];
244262
});
245263

246-
const hash = getShaFromData(dataToHash);
264+
const hash = req.headers['x-mock-hash'] || getShaFromData(dataToHash);
247265

248266
if (recordingsContext.active) {
249267
try {

0 commit comments

Comments
 (0)