|
| 1 | +/** |
| 2 | + * Copyright (C) 2023 Green Code Initiative |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +"use strict"; |
| 18 | +//------------------------------------------------------------------------------ |
| 19 | +// Requirements |
| 20 | +//------------------------------------------------------------------------------ |
| 21 | + |
| 22 | +const rule = require("../../../lib/rules/limit-db-query-results"), |
| 23 | + RuleTester = require("eslint").RuleTester; |
| 24 | + |
| 25 | +//------------------------------------------------------------------------------ |
| 26 | +// Tests |
| 27 | +//------------------------------------------------------------------------------ |
| 28 | + |
| 29 | +const ruleTester = new RuleTester({ |
| 30 | + parserOptions: { |
| 31 | + ecmaVersion: 6, |
| 32 | + sourceType: "module", |
| 33 | + }, |
| 34 | +}); |
| 35 | +const expectedError = { |
| 36 | + messageId: "LimitTheNumberOfReturns", |
| 37 | + type: "Literal", |
| 38 | +}; |
| 39 | + |
| 40 | +ruleTester.run("limit-db-query-results", rule, { |
| 41 | + valid: [ |
| 42 | + ` |
| 43 | + const query = "SELECT * FROM customers LIMIT 10;"; |
| 44 | + `, |
| 45 | + ` |
| 46 | + const query = "SELECT TOP 5 * FROM products;"; |
| 47 | + `, |
| 48 | + ` |
| 49 | + const query = "SELECT * FROM orders FETCH FIRST 20 ROWS ONLY;"; |
| 50 | + `, |
| 51 | + ` |
| 52 | + const query = "WITH numbered_customers AS (SELECT *, ROW_NUMBER() OVER (ORDER BY customer_id) AS row_num FROM customers) SELECT * FROM numbered_customers WHERE row_num <= 50;"; |
| 53 | + `, |
| 54 | + ], |
| 55 | + |
| 56 | + invalid: [ |
| 57 | + { |
| 58 | + code: `const query = "SELECT * FROM bikes;";`, |
| 59 | + errors: [expectedError], |
| 60 | + }, |
| 61 | + ], |
| 62 | +}); |
0 commit comments