Skip to content

Commit 910064e

Browse files
authored
feat: manage installation and autodraft (#74)
* feat: manage installation and autodraft * fix: feedbacks
1 parent a829935 commit 910064e

33 files changed

Lines changed: 1123 additions & 123 deletions

freshdesk-app/__mocks__/freshworks-crayons-react.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ export function FwButton(props) {
77
</button>
88
)
99
}
10+
11+
export const FwTextarea = React.forwardRef(function FwTextarea(props, ref) {
12+
return <textarea {...props} ref={ref} onChange={() => {}} />
13+
})

freshdesk-app/config/iparams.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,23 @@
44
"type": "text",
55
"required": true,
66
"secure": true
7+
},
8+
"freshdeskApiKey": {
9+
"display_name": "Freshdesk API Key",
10+
"description": "Follow this tutorial to get your API key: https://support.freshdesk.com/support/solutions/articles/215517-how-to-find-your-api-key",
11+
"type": "text",
12+
"required": true,
13+
"secure": true
14+
},
15+
"email": {
16+
"display_name": "Email",
17+
"type": "text",
18+
"required": true
19+
},
20+
"historicalLookupWindow": {
21+
"display_name": "Historical lookup window in days (default: 180)",
22+
"description": "Defines how far back (in days) Quivr will retrieve historical tickets to use as context when generating responses.",
23+
"type": "number",
24+
"required": false
725
}
826
}

freshdesk-app/config/requests.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,30 @@
99
"Content-Type": "application/json"
1010
}
1111
}
12+
},
13+
"createHelpdeskAccount": {
14+
"schema": {
15+
"method": "POST",
16+
"host": "<%= app_settings.quivrApiUrl %>",
17+
"path": "/helpdesk-accounts",
18+
"headers": {
19+
"Authorization": "Bearer <%= iparam.quivrApiKey %>",
20+
"Content-Type": "application/json"
21+
}
22+
}
23+
},
24+
"getAutodraft": {
25+
"schema": {
26+
"method": "GET",
27+
"host": "<%= app_settings.quivrApiUrl %>",
28+
"path": "/helpdesk-accounts/autodraft",
29+
"headers": {
30+
"Authorization": "Bearer <%= iparam.quivrApiKey %>",
31+
"Content-Type": "application/json"
32+
},
33+
"query": {
34+
"helpdesk_ticket_id": "<%= context.ticket_id %>"
35+
}
36+
}
1237
}
1338
}

freshdesk-app/global.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
declare module "*.scss" {
2-
const content: { [className: string]: string };
3-
export default content;
1+
declare module '*.scss' {
2+
const content: { [className: string]: string }
3+
export default content
44
}
55

6-
declare module "*.css" {
7-
const content: { [className: string]: string };
8-
export default content;
6+
declare module '*.css' {
7+
const content: { [className: string]: string }
8+
export default content
99
}

freshdesk-app/jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
setupFilesAfterEnv: ['<rootDir>/setUpTests.js'],
3+
testEnvironment: 'jsdom',
34
transform: { '^.+\\.[jt]sx?$': 'babel-jest' },
45
transformIgnorePatterns: [
56
'/node_modules/(?!(?:@freshworks/crayons)/)' // laissez Jest transpiler ce module
@@ -9,5 +10,6 @@ module.exports = {
910
'\\.(css|less|scss|sss|styl)$': '<rootDir>/node_modules/jest-css-modules'
1011
},
1112
coverageReporters: [['json'], ['lcov']],
12-
testMatch: ['**/*.test.(js|jsx)']
13+
testMatch: ['**/*.test.(js|jsx)'],
14+
testPathIgnorePatterns: ['<rootDir>/test/server.test.js']
1315
}

freshdesk-app/manifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
}
99
},
1010
"requests": {
11-
"getHelpdeskAccount": {}
11+
"getHelpdeskAccount": {},
12+
"createHelpdeskAccount": {},
13+
"getAutodraft": {}
1214
}
1315
},
1416
"support_ticket": {

freshdesk-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@babel/preset-typescript": "^7.27.1",
2121
"@testing-library/jest-dom": "^5.11.6",
2222
"@testing-library/react": "^11.1.0",
23+
"@testing-library/react-hooks": "^8.0.1",
2324
"@testing-library/user-event": "^12.1.10",
2425
"@types/node": "^24.1.0",
2526
"@types/react": "^17.0.1",

freshdesk-app/public/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Quivr App</title>
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@freshworks/crayons@v4/css/crayons-min.css" />
78
</head>
89
<body>
910
<div class="" id="root"></div>

freshdesk-app/server/server.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
exports = {
2-
onAppInstallHandler: function (payload) {
3-
console.log('Logging arguments from onAppInstallevent: ' + JSON.stringify(payload))
4-
// If the setup is successful
5-
renderData()
2+
onAppInstallHandler: async function (payload) {
3+
console.log('onAppInstallHandler invoked with following data: \n', payload)
4+
try {
5+
await $request.invokeTemplate('createHelpdeskAccount', {
6+
body: JSON.stringify({
7+
subdomain: payload.currentHost.endpoint_urls.freshdesk.split('//')[1],
8+
api_key: payload.iparams.freshdeskApiKey,
9+
email: payload.iparams.email,
10+
provider: 'freshdesk',
11+
time_range: payload.iparams.historicalLookupWindow || 180
12+
})
13+
})
14+
renderData()
15+
} catch (error) {
16+
renderData({ message: 'Failed to create helpdesk account' })
17+
}
618
},
719
onSettingsUpdate: function (args) {
8-
// args is a JSON block containing the payload information
9-
// include logic to validate the app settings
1020
console.log('onSettingsUpdate invoked with following data: \n', args)
1121
renderData()
1222
}

freshdesk-app/src/App.test.tsx

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,29 @@ import { screen, render } from '@testing-library/react'
22
import App from './App'
33

44
// Mock the context to provide a client
5-
jest.mock('./context/FreshdeskClientContext', () => ({
5+
jest.mock('./context/FreshdeskClientContext/FreshdeskClientContext', () => ({
66
useFreshdeskClient: jest.fn()
77
}))
88

99
jest.mock('@freshworks/crayons/react', () => require('../__mocks__/freshworks-crayons-react'))
1010

11-
test('renders the app with HelloUser component', () => {
12-
// Mock the context to return a client
13-
const { useFreshdeskClient } = require('./context/FreshdeskClientContext')
14-
useFreshdeskClient.mockReturnValue({
15-
// Mock client object
16-
})
17-
18-
render(<App />)
19-
20-
// Check for the button text
21-
const buttonElement = screen.getByText(/get helpdesk account/i)
22-
expect(buttonElement).toBeInTheDocument()
23-
24-
// Check for the welcome text
25-
const welcomeText = screen.getByText(/welcome to your first react app in freshdesk/i)
26-
expect(welcomeText).toBeInTheDocument()
11+
// Mock ResponseContainer component
12+
jest.mock('./components/ResponseContainer/ResponseContainer', () => {
13+
return function MockResponseContainer() {
14+
return 'MOCK_RESPONSE_CONTAINER'
15+
}
2716
})
2817

29-
test('renders loading state when client is not available', () => {
30-
// Mock the context to return null client
31-
const { useFreshdeskClient } = require('./context/FreshdeskClientContext')
32-
useFreshdeskClient.mockReturnValue(null)
18+
// Mock AccountConfigContext
19+
jest.mock('./context/AccountConfigContext/AccountConfigContext', () => ({
20+
AccountConfigProvider: ({ children }: { children: any }) => children
21+
}))
22+
23+
test('renders App component', () => {
24+
const { useFreshdeskClient } = require('./context/FreshdeskClientContext/FreshdeskClientContext')
25+
useFreshdeskClient.mockReturnValue({})
3326

3427
render(<App />)
3528

36-
const loadingElement = screen.getByText(/loading/i)
37-
expect(loadingElement).toBeInTheDocument()
29+
expect(screen.getByText('MOCK_RESPONSE_CONTAINER')).toBeInTheDocument()
3830
})

0 commit comments

Comments
 (0)