diff --git a/src/code.js b/src/code.js new file mode 100644 index 000000000..3311f61e3 --- /dev/null +++ b/src/code.js @@ -0,0 +1,8 @@ + { + "code": "// Function to handle spam reporting +function reportSpam(user, reason) {\n // Validate inputs\n if (typeof user !== 'string' || typeof reason !== 'string') {\n throw new Error('Invalid input');\n }\n\n // Simulate a request to the GitHub API for reporting spam\n const report = { status: 'success', message: 'Spam reported successfully' };\n if (report.status === 'success') {\n console.log(report.message);\n } else {\n throw new Error('Failed to report spam');\n }\n}\n\n// Example usage:\n// reportSpam('spamUser', 'This user is spamming the repository.');", + "filename": "reportSpam.js", + "explanation": "This function handles the reporting of spam by validating inputs and simulating a request to the GitHub API for reporting spam.", + "testCode": "// Test cases for reportSpam function\nconst assert = require('assert');\ntry {\n reportSpam('validUser', 'validReason');\n} catch (e) {\n console.error(e.message);\n}\ntry {\n reportSpam(123, 'invalidInput');\n} catch (e) {\n console.error(e.message);\n}\ntry {\n reportSpam('spamUser', {});\n} catch (e) {\n console.error(e.message);\n}", + "testFilename": "testReportSpam.js" +} \ No newline at end of file