@@ -2,7 +2,7 @@ import atlassianProjectsController from './atlassian.projects.controller.js';
22import { getAtlassianCredentials } from '../utils/transport.util.js' ;
33import { config } from '../utils/config.util.js' ;
44import { McpError } from '../utils/error.util.js' ; // Import McpError
5- import { formatSeparator , formatDate } from '../utils/formatter.util.js' ; // Add imports
5+ import { formatSeparator } from '../utils/formatter.util.js' ; // Add imports
66
77describe ( 'Atlassian Projects Controller' , ( ) => {
88 // Load configuration and check for credentials before all tests
@@ -29,25 +29,10 @@ describe('Atlassian Projects Controller', () => {
2929 expect ( result ) . toBeDefined ( ) ;
3030 expect ( result ) . toHaveProperty ( 'content' ) ;
3131 expect ( typeof result . content ) . toBe ( 'string' ) ;
32- expect ( result ) . toHaveProperty ( 'pagination' ) ;
33-
34- // Check pagination object structure and basic types
35- expect ( result . pagination ) . toBeDefined ( ) ;
36- expect ( result . pagination ) . toHaveProperty ( 'hasMore' ) ;
37- expect ( typeof result . pagination ?. hasMore ) . toBe ( 'boolean' ) ;
38- expect ( result . pagination ) . toHaveProperty ( 'count' ) ;
39- expect ( typeof result . pagination ?. count ) . toBe ( 'number' ) ;
40- expect ( result . pagination ) . toHaveProperty ( 'total' ) ;
41- expect ( typeof result . pagination ?. total ) . toBe ( 'number' ) ;
42- if ( result . pagination ?. hasMore ) {
43- expect ( result . pagination ) . toHaveProperty ( 'nextCursor' ) ;
44- expect ( typeof result . pagination ?. nextCursor ) . toBe ( 'string' ) ;
45- }
4632
4733 // Check that content does NOT contain pagination string anymore
48- expect ( result . content ) . not . toContain ( 'Showing' ) ;
49- expect ( result . content ) . not . toContain ( 'Next StartAt' ) ;
50- expect ( result . content ) . not . toContain ( `total items` ) ;
34+ expect ( result . content ) . toContain ( 'Showing' ) ;
35+ expect ( result . content ) . toContain ( 'total items' ) ;
5136
5237 // Basic Markdown content checks - check for expected formatting from live data
5338 if (
@@ -67,31 +52,31 @@ describe('Atlassian Projects Controller', () => {
6752 const result1 = await atlassianProjectsController . list ( {
6853 limit : 1 ,
6954 } ) ;
70- expect ( result1 . pagination ?. count ) . toBeLessThanOrEqual ( 1 ) ;
71-
72- // If there's a next page, fetch it
73- if ( result1 . pagination ?. hasMore && result1 . pagination . nextCursor ) {
74- // Parse the nextCursor (which is the next startAt value as a string)
75- const nextStartAt = parseInt ( result1 . pagination . nextCursor , 10 ) ;
76- if ( isNaN ( nextStartAt ) ) {
77- throw new Error (
78- `Invalid nextCursor format for startAt: ${ result1 . pagination . nextCursor } ` ,
79- ) ;
80- }
81- const result2 = await atlassianProjectsController . list ( {
82- limit : 1 ,
83- // Pass the parsed number as startAt
84- startAt : nextStartAt ,
85- } ) ;
86- expect ( result2 . pagination ?. count ) . toBeLessThanOrEqual ( 1 ) ;
87- // Check if content is different (simple check)
88- if (
89- result1 . content !==
90- 'No Jira projects found matching your criteria.' &&
91- result2 . content !==
92- 'No Jira projects found matching your criteria.'
93- ) {
94- expect ( result1 . content ) . not . toEqual ( result2 . content ) ;
55+
56+ // Check if content contains pagination information
57+ if ( result1 . content . includes ( 'More results are available' ) ) {
58+ // Get the next startAt value from the content
59+ const startAtMatch = result1 . content . match (
60+ / U s e - - s t a r t - a t ( \d + ) t o v i e w m o r e / ,
61+ ) ;
62+ if ( startAtMatch && startAtMatch [ 1 ] ) {
63+ const nextStartAt = parseInt ( startAtMatch [ 1 ] , 10 ) ;
64+
65+ // Fetch second page
66+ const result2 = await atlassianProjectsController . list ( {
67+ limit : 1 ,
68+ startAt : nextStartAt ,
69+ } ) ;
70+
71+ // If both results have content, they should be different
72+ if (
73+ result1 . content !==
74+ 'No Jira projects found matching your criteria.' &&
75+ result2 . content !==
76+ 'No Jira projects found matching your criteria.'
77+ ) {
78+ expect ( result1 . content ) . not . toEqual ( result2 . content ) ;
79+ }
9580 }
9681 } else {
9782 console . warn (
@@ -131,13 +116,14 @@ describe('Atlassian Projects Controller', () => {
131116 limit : 5 ,
132117 } ) ;
133118
134- expect ( result . pagination ?. count ) . toBeLessThanOrEqual ( 5 ) ;
119+ // Check if the content is well-formed
135120 if (
136121 result . content !==
137122 'No Jira projects found matching your criteria.'
138123 ) {
139124 expect ( result . content ) . toMatch ( / ^ # J i r a P r o j e c t s / m) ;
140- // Further checks could involve verifying sorting/filtering in Markdown, but that's complex
125+ // Content should contain pagination information
126+ expect ( result . content ) . toContain ( 'Information retrieved at:' ) ;
141127 }
142128 } , 30000 ) ;
143129
@@ -155,21 +141,15 @@ describe('Atlassian Projects Controller', () => {
155141 expect ( typeof result . content ) . toBe ( 'string' ) ;
156142
157143 // Check specific empty result message including the standard footer
158- expect ( result . content ) . toBe (
159- 'No Jira projects found matching your criteria.\n\n' +
160- formatSeparator ( ) +
161- '\n' +
162- `*Information retrieved at: ${ formatDate ( new Date ( ) ) } *` ,
144+ expect ( result . content ) . toContain (
145+ 'No Jira projects found matching your criteria' ,
163146 ) ;
164- // Verify pagination properties for empty result
165- expect ( result . pagination ) . toHaveProperty ( 'count' , 0 ) ;
166- expect ( result . pagination ?. hasMore ) . toBe ( false ) ;
167- expect ( result . pagination ?. total ) . toBe ( 0 ) ;
168- expect ( result . pagination ?. nextCursor ) . toBeUndefined ( ) ;
147+ expect ( result . content ) . toContain ( formatSeparator ( ) ) ;
148+ expect ( result . content ) . toContain ( 'Information retrieved at:' ) ;
169149
170150 // Check that content does NOT contain pagination string
171- expect ( result . content ) . not . toContain ( 'Showing' ) ;
172- expect ( result . content ) . not . toContain ( 'Next StartAt ' ) ;
151+ expect ( result . content ) . toContain ( 'Showing' ) ;
152+ expect ( result . content ) . toContain ( 'total items ' ) ;
173153 } , 30000 ) ;
174154
175155 it ( 'should handle various filtering combinations' , async ( ) => {
@@ -211,11 +191,9 @@ describe('Atlassian Projects Controller', () => {
211191 // Verify response (might find 0 or 1 projects due to exact matching)
212192 expect ( result ) . toHaveProperty ( 'content' ) ;
213193 expect ( typeof result . content ) . toBe ( 'string' ) ;
214- expect ( result ) . toHaveProperty ( 'pagination' ) ;
215- expect ( result . pagination ) . toHaveProperty ( 'count' ) ;
216194
217195 // If we found exactly the project we filtered for, its key should be in the content
218- if ( result . pagination ?. count === 1 ) {
196+ if ( result . content . includes ( projectKey ) ) {
219197 expect ( result . content ) . toContain ( `**Key**: ${ projectKey } ` ) ;
220198 }
221199 } , 30000 ) ;
@@ -231,21 +209,16 @@ describe('Atlassian Projects Controller', () => {
231209 limit : 10 ,
232210 } ) ;
233211
234- expect ( result . content ) . toBe (
235- 'No Jira projects found matching your criteria.\n\n' +
236- formatSeparator ( ) +
237- '\n' +
238- `*Information retrieved at: ${ formatDate ( new Date ( ) ) } *` ,
239- ) ; // Check actual empty message
240- expect ( result . pagination ) . toBeDefined ( ) ;
241- expect ( result . pagination ?. hasMore ) . toBe ( false ) ;
242- expect ( result . pagination ?. count ) . toBe ( 0 ) ;
243- expect ( result . pagination ?. total ) . toBe ( 0 ) ;
244- expect ( result . pagination ?. nextCursor ) . toBeUndefined ( ) ;
212+ // Check actual empty message and formatting
213+ expect ( result . content ) . toContain (
214+ 'No Jira projects found matching your criteria' ,
215+ ) ;
216+ expect ( result . content ) . toContain ( formatSeparator ( ) ) ;
217+ expect ( result . content ) . toContain ( 'Information retrieved at:' ) ;
245218
246219 // Check that content does NOT contain pagination string anymore
247- expect ( result . content ) . not . toContain ( 'Showing' ) ;
248- expect ( result . content ) . not . toContain ( 'Next StartAt ' ) ;
220+ expect ( result . content ) . toContain ( 'Showing' ) ;
221+ expect ( result . content ) . toContain ( 'total items ' ) ;
249222 } , 30000 ) ;
250223 } ) ;
251224
@@ -297,7 +270,6 @@ describe('Atlassian Projects Controller', () => {
297270 // Verify the ControllerResponse structure
298271 expect ( result ) . toHaveProperty ( 'content' ) ;
299272 expect ( typeof result . content ) . toBe ( 'string' ) ;
300- expect ( result ) . not . toHaveProperty ( 'pagination' ) ; // 'get' shouldn't have pagination
301273
302274 // Verify Markdown content
303275 expect ( result . content ) . toMatch ( / ^ # P r o j e c t : / m) ; // Main heading for project details
0 commit comments