diff --git a/tests/__mocks__/configurations/custom-configuration-decoded.json b/tests/__mocks__/configurations/custom-configuration-decoded.json new file mode 100644 index 00000000..89b75f6e --- /dev/null +++ b/tests/__mocks__/configurations/custom-configuration-decoded.json @@ -0,0 +1,416 @@ +{ + "default": { + "dataCollection": { + "delayMs": 1000, + "maxAttempts": 10 + }, + "erc20RewardToken": "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d", + "evmNetworkId": 100, + "evmPrivateEncrypted": "1234", + "incentives": { + "contentEvaluator": { + "multipliers": [ + { + "relevance": 1, + "role": [ + "ISSUE_SPECIFICATION" + ] + } + ], + "openAi": { + "endpoint": "", + "model": "gpt-4o-2024-08-06" + } + }, + "dataPurge": {}, + "formattingEvaluator": { + "multipliers": [ + { + "multiplier": 3, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.1 + }, + "role": [ + "ISSUE_SPECIFICATION" + ] + }, + { + "multiplier": 1, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.1 + }, + "role": [ + "ISSUE_AUTHOR", + "ISSUE_COLLABORATOR", + "PULL_COLLABORATOR" + ] + }, + { + "multiplier": 0.25, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.1 + }, + "role": [ + "ISSUE_CONTRIBUTOR", + "PULL_CONTRIBUTOR" + ] + }, + { + "multiplier": 0, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0 + }, + "role": [ + "PULL_SPECIFICATION", + "PULL_AUTHOR", + "ISSUE_ASSIGNEE", + "PULL_ASSIGNEE" + ] + } + ], + "wordCountExponent": 0.85 + }, + "githubComment": { + "debug": false, + "post": true + }, + "permitGeneration": { + "enabled": true + }, + "requirePriceLabel": true, + "userExtractor": { + "enabled": true, + "redeemTask": true + } + }, + "logLevel": "debug" + } +} \ No newline at end of file diff --git a/tests/__mocks__/configurations/custom-configuration.json b/tests/__mocks__/configurations/custom-configuration.json new file mode 100644 index 00000000..d7cc758e --- /dev/null +++ b/tests/__mocks__/configurations/custom-configuration.json @@ -0,0 +1,32 @@ +{ + "logLevel": "debug", + "evmNetworkId": 100, + "evmPrivateEncrypted": "1234", + "erc20RewardToken": "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d", + "incentives": { + "requirePriceLabel": true, + "contentEvaluator": {}, + "userExtractor": { "enabled": true, "redeemTask": true }, + "dataPurge": {}, + "formattingEvaluator": { + "multipliers": [ + { "role": ["ISSUE_SPECIFICATION"], "multiplier": 3, "rewards": { "wordValue": 0.1 } }, + { + "role": ["ISSUE_AUTHOR", "ISSUE_COLLABORATOR", "PULL_COLLABORATOR"], + "multiplier": 1, + "rewards": { "wordValue": 0.1 } + }, + { "role": ["ISSUE_CONTRIBUTOR", "PULL_CONTRIBUTOR"], "multiplier": 0.25, "rewards": { "wordValue": 0.1 } }, + { + "role": ["PULL_SPECIFICATION", "PULL_AUTHOR", "ISSUE_ASSIGNEE", "PULL_ASSIGNEE"], + "multiplier": 0, + "rewards": { "wordValue": 0 } + } + ], + "wordCountExponent": 0.85 + }, + "permitGeneration": { "enabled": true }, + "githubComment": { "post": true, "debug": false } + }, + "dataCollection": { "maxAttempts": 10, "delayMs": 1000 } +} diff --git a/tests/__mocks__/configurations/default-configuration.json b/tests/__mocks__/configurations/default-configuration.json new file mode 100644 index 00000000..19138b91 --- /dev/null +++ b/tests/__mocks__/configurations/default-configuration.json @@ -0,0 +1,953 @@ +{ + "default": { + "dataCollection": { + "delayMs": 1000, + "maxAttempts": 10 + }, + "erc20RewardToken": "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d", + "evmNetworkId": 100, + "evmPrivateEncrypted": "1234", + "incentives": { + "contentEvaluator": { + "multipliers": [ + { + "relevance": 1, + "role": [ + "ISSUE_SPECIFICATION" + ] + } + ], + "openAi": { + "endpoint": "", + "model": "gpt-4o-2024-08-06" + } + }, + "dataPurge": {}, + "formattingEvaluator": { + "multipliers": [ + { + "multiplier": 1, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.1 + }, + "role": [ + "ISSUE_SPECIFICATION" + ] + }, + { + "multiplier": 1, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.2 + }, + "role": [ + "ISSUE_AUTHOR" + ] + }, + { + "multiplier": 0, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0 + }, + "role": [ + "ISSUE_ASSIGNEE" + ] + }, + { + "multiplier": 1, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.1 + }, + "role": [ + "ISSUE_COLLABORATOR" + ] + }, + { + "multiplier": 0.25, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.1 + }, + "role": [ + "ISSUE_CONTRIBUTOR" + ] + }, + { + "multiplier": 0, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0 + }, + "role": [ + "PULL_SPECIFICATION" + ] + }, + { + "multiplier": 2, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.2 + }, + "role": [ + "PULL_AUTHOR" + ] + }, + { + "multiplier": 1, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.1 + }, + "role": [ + "PULL_ASSIGNEE" + ] + }, + { + "multiplier": 1, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.1 + }, + "role": [ + "PULL_COLLABORATOR" + ] + }, + { + "multiplier": 0.25, + "rewards": { + "html": { + "a": { + "countWords": true, + "score": 5 + }, + "blockquote": { + "countWords": false, + "score": 0 + }, + "br": { + "countWords": true, + "score": 0 + }, + "code": { + "countWords": false, + "score": 5 + }, + "em": { + "countWords": true, + "score": 0 + }, + "h1": { + "countWords": true, + "score": 1 + }, + "h2": { + "countWords": true, + "score": 1 + }, + "h3": { + "countWords": true, + "score": 1 + }, + "h4": { + "countWords": true, + "score": 1 + }, + "h5": { + "countWords": true, + "score": 1 + }, + "h6": { + "countWords": true, + "score": 1 + }, + "hr": { + "countWords": true, + "score": 0 + }, + "img": { + "countWords": true, + "score": 5 + }, + "li": { + "countWords": true, + "score": 0.5 + }, + "ol": { + "countWords": true, + "score": 1 + }, + "p": { + "countWords": true, + "score": 0 + }, + "pre": { + "countWords": false, + "score": 0 + }, + "strong": { + "countWords": false, + "score": 0 + }, + "td": { + "countWords": true, + "score": 0 + }, + "ul": { + "countWords": true, + "score": 1 + } + }, + "wordValue": 0.1 + }, + "role": [ + "PULL_CONTRIBUTOR" + ] + } + ], + "wordCountExponent": 0.85 + }, + "githubComment": { + "debug": false, + "post": true + }, + "permitGeneration": {}, + "requirePriceLabel": true, + "userExtractor": { + "redeemTask": true + } + }, + "logLevel": "info" + } +} \ No newline at end of file diff --git a/tests/configuration.test.ts b/tests/configuration.test.ts new file mode 100644 index 00000000..5449a915 --- /dev/null +++ b/tests/configuration.test.ts @@ -0,0 +1,69 @@ +import validConfiguration from "./__mocks__/configurations/default-configuration.json"; +import customConfigurationDecoded from "./__mocks__/configurations/custom-configuration-decoded.json"; + +describe("Configuration", () => { + beforeEach(() => { + jest.resetModules(); + jest.resetAllMocks(); + }); + it("should match the valid configuration", async () => { + jest.mock("@actions/github", () => ({ + context: { + runId: "1", + payload: { + repository: { + html_url: "https://github.com/ubiquity-os/conversation-rewards", + }, + inputs: { + stateId: "12345", + eventName: "issues.closed", + authToken: "", + ref: "main", + eventPayload: JSON.stringify({}), + settings: JSON.stringify({ + evmPrivateEncrypted: "1234", + incentives: { + contentEvaluator: {}, + dataPurge: {}, + formattingEvaluator: {}, + githubComment: {}, + permitGeneration: {}, + requirePriceLabel: true, + userExtractor: {}, + }, + }), + }, + }, + sha: "1234", + }, + })); + const configuration = await import("../src/configuration/config-reader"); + expect(configuration).toEqual(validConfiguration); + }); + it("should match the custom configuration", async () => { + jest.mock("@actions/github", () => { + const cfg = require("./__mocks__/configurations/custom-configuration.json"); + return { + context: { + runId: "1", + payload: { + repository: { + html_url: "https://github.com/ubiquity-os/conversation-rewards", + }, + inputs: { + stateId: "12345", + eventName: "issues.closed", + authToken: "", + ref: "main", + eventPayload: JSON.stringify({}), + settings: JSON.stringify(cfg), + }, + }, + sha: "1234", + }, + }; + }); + const configuration = await import("../src/configuration/config-reader"); + expect(configuration).toEqual(customConfigurationDecoded); + }); +});