1- const { ESLintUtils } = require ( "@typescript-eslint/utils" ) ;
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+ //------------------------------------------------------------------------------
20+ // Requirements
21+ //------------------------------------------------------------------------------
22+
223const rule = require ( "../../../lib/rules/prefer-collections-with-pagination" ) ;
24+ const RuleTester = require ( "eslint" ) . RuleTester ;
25+
26+ //------------------------------------------------------------------------------
27+ // Tests
28+ //------------------------------------------------------------------------------
329
4- const ruleTester = new ESLintUtils . RuleTester ( {
5- parser : "@typescript-eslint/parser" ,
30+ const ruleTester = new RuleTester ( {
31+ parser : require . resolve ( "@typescript-eslint/parser" ) ,
632} ) ;
733
8- const expectedError = {
34+ const expectedArrayError = {
935 messageId : "PreferReturnCollectionsWithPagination" ,
10- type : "Decorator" ,
36+ type : "TSArrayType" ,
37+ } ;
38+ const expectedReferenceError = {
39+ messageId : "PreferReturnCollectionsWithPagination" ,
40+ type : "TSTypeReference" ,
1141} ;
1242
1343ruleTester . run ( "prefer-collections-with-pagination" , rule , {
@@ -28,6 +58,20 @@ ruleTester.run("prefer-collections-with-pagination", rule, {
2858 ` ,
2959 `
3060 @Controller()
61+ public class Test {
62+ @Get()
63+ public find() {}
64+ }
65+ ` ,
66+ `
67+ @Controller()
68+ public class Test {
69+ @Get(':id')
70+ public findOne(): Promise<string> {}
71+ }
72+ ` ,
73+ `
74+ @Controller()
3175 public class Test {
3276 @Get()
3377 public find(): Promise<{items: string[], currentPage: number, totalPages: number}> {}
@@ -43,7 +87,17 @@ ruleTester.run("prefer-collections-with-pagination", rule, {
4387 public find(): Promise<string[]> {}
4488 }
4589 ` ,
46- errors : [ expectedError ] ,
90+ errors : [ expectedReferenceError ] ,
91+ } ,
92+ {
93+ code : `
94+ @Controller()
95+ public class Test {
96+ @Get()
97+ public find(): Promise<ClassicList> {}
98+ }
99+ ` ,
100+ errors : [ expectedReferenceError ] ,
47101 } ,
48102 {
49103 code : `
@@ -53,7 +107,7 @@ ruleTester.run("prefer-collections-with-pagination", rule, {
53107 public find(): string[] {}
54108 }
55109 ` ,
56- errors : [ expectedError ] ,
110+ errors : [ expectedArrayError ] ,
57111 } ,
58112 {
59113 code : `
@@ -63,7 +117,7 @@ ruleTester.run("prefer-collections-with-pagination", rule, {
63117 public find(): Promise<{items: string[]}> {}
64118 }
65119 ` ,
66- errors : [ expectedError ] ,
120+ errors : [ expectedReferenceError ] ,
67121 } ,
68122 ] ,
69123} ) ;
0 commit comments