Skip to content

Commit 9d304d6

Browse files
committed
feat: format response
1 parent 9961925 commit 9d304d6

File tree

5 files changed

+117
-8
lines changed

5 files changed

+117
-8
lines changed

β€Ž__tests__/main.test.tsβ€Ž

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jest.unstable_mockModule('formdata-node/file-from-path', () => ({
2626

2727
// The module being tested should be imported dynamically. This ensures that the
2828
// mocks are used in place of any actual dependencies.
29-
const { run } = await import('../src/main.ts')
29+
const { run, formatPumpRoomResponse } = await import('../src/main.ts')
3030

3131
describe('main.ts', () => {
3232
const mockRootDir = '/mock/root/dir'
@@ -67,10 +67,19 @@ describe('main.ts', () => {
6767
}
6868
})
6969

70-
// Set up axios mock
70+
// Set up axios mock with the expected response format
7171
axios.post.mockResolvedValue({
7272
status: 200,
73-
data: { success: true }
73+
data: {
74+
repo_updated: true,
75+
pushed_at: '2025-07-30T21:26:10.875969',
76+
tasks_current: 33,
77+
tasks_updated: 33,
78+
tasks_created: 0,
79+
tasks_deleted: 1,
80+
tasks_cached: 33,
81+
tasks_synchronized_with_cms: 2
82+
}
7483
})
7584

7685
// Set up FormData mock
@@ -93,6 +102,38 @@ describe('main.ts', () => {
93102

94103
// Verify success message was logged
95104
expect(core.info).toHaveBeenCalled()
105+
106+
// Since we're mocking the API response and not actually calling the real API,
107+
// we can't directly test the formatted output in this test.
108+
// The formatting functionality is tested separately in the "Formats the API response correctly" test.
109+
})
110+
111+
it('Formats the API response correctly', () => {
112+
// Create a sample response object
113+
const sampleResponse = {
114+
repo_updated: true,
115+
pushed_at: '2025-07-30T21:26:10.875969',
116+
tasks_current: 33,
117+
tasks_updated: 33,
118+
tasks_created: 0,
119+
tasks_deleted: 1,
120+
tasks_cached: 33,
121+
tasks_synchronized_with_cms: 2
122+
}
123+
124+
// Format the response
125+
const formattedResponse = formatPumpRoomResponse(sampleResponse)
126+
127+
// Verify the formatted response contains the expected information
128+
expect(formattedResponse).toContain('PumpRoom Repository Update Summary')
129+
expect(formattedResponse).toContain('Repository Updated: Yes')
130+
expect(formattedResponse).toContain('Tasks Summary')
131+
expect(formattedResponse).toContain('Current: 33')
132+
expect(formattedResponse).toContain('Updated: 33')
133+
expect(formattedResponse).toContain('Created: 0')
134+
expect(formattedResponse).toContain('Deleted: 1')
135+
expect(formattedResponse).toContain('Cached: 33')
136+
expect(formattedResponse).toContain('Synchronized with CMS: 2')
96137
})
97138

98139
it('Handles API error correctly', async () => {

β€Žbadges/coverage.svgβ€Ž

Lines changed: 1 addition & 1 deletion
Loading

β€Ždist/index.jsβ€Ž

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ždist/index.js.mapβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žsrc/main.tsβ€Ž

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,46 @@ import axios from 'axios'
66
import { FormData } from 'formdata-node'
77
import { fileFromPath } from 'formdata-node/file-from-path'
88

9+
/**
10+
* Interface for the PumpRoom API response
11+
*/
12+
export interface PumpRoomApiResponse {
13+
repo_updated: boolean
14+
pushed_at: string
15+
tasks_current: number
16+
tasks_updated: number
17+
tasks_created: number
18+
tasks_deleted: number
19+
tasks_cached: number
20+
tasks_synchronized_with_cms: number
21+
}
22+
23+
/**
24+
* Formats the PumpRoom API response for better readability in console output
25+
*
26+
* @param response - The API response to format
27+
* @returns A formatted string representation of the response
28+
*/
29+
export function formatPumpRoomResponse(response: PumpRoomApiResponse): string {
30+
const date = new Date(response.pushed_at)
31+
const formattedDate = date.toLocaleString()
32+
return `
33+
πŸ“Š PumpRoom Repository Update Summary:
34+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
35+
βœ… Repository Updated: ${response.repo_updated ? 'Yes' : 'No'}
36+
πŸ•’ Pushed At: ${formattedDate}
37+
38+
πŸ“‹ Tasks Summary:
39+
β€’ Current: ${response.tasks_current}
40+
β€’ Updated: ${response.tasks_updated}
41+
β€’ Created: ${response.tasks_created}
42+
β€’ Deleted: ${response.tasks_deleted}
43+
β€’ Cached: ${response.tasks_cached}
44+
β€’ Synchronized with CMS: ${response.tasks_synchronized_with_cms}
45+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
46+
`
47+
}
48+
949
/**
1050
* The main function for the action.
1151
*
@@ -152,11 +192,12 @@ async function uploadArchive(
152192
)
153193

154194
core.info(`Response status: ${response.status}`)
155-
core.info(`Response: ${JSON.stringify(response.data)}`)
156-
157195
if (response.status !== 200) {
158196
throw new Error(`Unable to register repo, code: ${response.status}`)
159197
} else {
198+
// Type the response data and format it for display
199+
const responseData = response.data as PumpRoomApiResponse
200+
core.info(formatPumpRoomResponse(responseData))
160201
core.info('βœ… Repo and tasks successfully registered')
161202
}
162203
} catch (error) {

0 commit comments

Comments
Β (0)