Skip to content

Commit

Permalink
mock historical prebuilt rule versions
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpn committed Sep 10, 2024
1 parent 7e61fad commit d72f1b4
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,24 @@ export const bulkCreateRuleAssets = ({
const url = `${Cypress.env('ELASTICSEARCH_URL')}/${index}/_bulk?refresh`;

const bulkIndexRequestBody = rules.reduce((body, rule) => {
const indexOperation = {
const document = JSON.stringify(rule);
const documentId = `security-rule:${rule['security-rule'].rule_id}`;
const historicalDocumentId = `${documentId}_${rule['security-rule'].version}`;

const indexRuleAsset = `${JSON.stringify({
index: {
_index: index,
_id: documentId,
},
})}\n${document}\n`;
const indexHistoricalRuleAsset = `${JSON.stringify({
index: {
_index: index,
_id: `security-rule:${rule['security-rule'].rule_id}`,
_id: historicalDocumentId,
},
};
})}\n${document}\n`;

const documentData = JSON.stringify(rule);
return body.concat(JSON.stringify(indexOperation), '\n', documentData, '\n');
return body.concat(indexRuleAsset, indexHistoricalRuleAsset);
}, '');

rootRequest({
Expand Down

0 comments on commit d72f1b4

Please sign in to comment.