-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathdeviceGroups_spec.js
More file actions
191 lines (151 loc) · 8.13 KB
/
Copy pathdeviceGroups_spec.js
File metadata and controls
191 lines (151 loc) · 8.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const should = require('should') // eslint-disable-line no-unused-vars
const { expectToolMatchesRoute, createExpertMcpToken, toolFinder, recordingInject } = require('../../../../../../lib/mcpToolEquivalence')
const FF_UTIL = require('flowforge-test-utils')
const tools = FF_UTIL.require('forge/ee/lib/mcp/tools/deviceGroups')
const findTool = toolFinder(tools)
describe('MCP Tools: deviceGroups', function () {
describe('platform_list_application_device_groups', function () {
const tool = findTool('platform_list_application_device_groups')
it('should be registered', function () {
should.exist(tool)
})
it('should be read-only and non-destructive', function () {
tool.annotations.should.have.property('readOnlyHint', true)
tool.annotations.should.have.property('destructiveHint', false)
})
it('should declare the expected input schema keys', function () {
Object.keys(tool.inputSchema).should.containDeep(['applicationId', 'cursor', 'limit', 'query'])
})
it('should GET the application device-groups endpoint', async function () {
const { calls, inject } = recordingInject()
await tool.handler({ applicationId: 'app123' }, { inject })
calls.should.have.length(1)
calls[0].should.have.property('method', 'GET')
calls[0].should.have.property('url', '/api/v1/applications/app123/device-groups')
})
it('should serialise the pagination query params onto the url', async function () {
const { calls, inject } = recordingInject()
await tool.handler({
applicationId: 'app123',
cursor: 'abc',
limit: 10,
query: 'foo bar'
}, { inject })
calls[0].url.should.equal('/api/v1/applications/app123/device-groups?cursor=abc&limit=10&query=foo+bar')
})
})
describe('platform_get_application_device_group', function () {
const tool = findTool('platform_get_application_device_group')
it('should be registered', function () {
should.exist(tool)
})
it('should be read-only and non-destructive', function () {
tool.annotations.should.have.property('readOnlyHint', true)
tool.annotations.should.have.property('destructiveHint', false)
})
it('should declare the expected input schema keys', function () {
Object.keys(tool.inputSchema).should.containDeep(['applicationId', 'groupId'])
})
it('should GET the single device-group endpoint', async function () {
const { calls, inject } = recordingInject()
await tool.handler({ applicationId: 'app123', groupId: 'group456' }, { inject })
calls.should.have.length(1)
calls[0].should.have.property('method', 'GET')
calls[0].should.have.property('url', '/api/v1/applications/app123/device-groups/group456')
})
})
describe('platform_list_team_device_groups', function () {
const tool = findTool('platform_list_team_device_groups')
it('should be registered', function () {
should.exist(tool)
})
it('should be read-only and non-destructive', function () {
tool.annotations.should.have.property('readOnlyHint', true)
tool.annotations.should.have.property('destructiveHint', false)
})
it('should declare the expected input schema keys', function () {
Object.keys(tool.inputSchema).should.containDeep(['teamId', 'cursor', 'limit', 'query'])
})
it('should GET the team device-groups endpoint', async function () {
const { calls, inject } = recordingInject()
await tool.handler({ teamId: 'team789' }, { inject })
calls.should.have.length(1)
calls[0].should.have.property('method', 'GET')
calls[0].should.have.property('url', '/api/v1/teams/team789/device-groups')
})
it('should serialise the pagination query params onto the url', async function () {
const { calls, inject } = recordingInject()
await tool.handler({ teamId: 'team789', limit: 5, query: 'fleet' }, { inject })
calls[0].url.should.equal('/api/v1/teams/team789/device-groups?limit=5&query=fleet')
})
})
describe('integration smoke', function () {
const setup = require('../../../setup')
let app
let token
before(async function () {
app = await setup({ ai: { enabled: true }, expert: { enabled: true } })
// Device groups are off by default; enable the feature flag so the smoke test hits the real route
const defaultTeamTypeProperties = app.defaultTeamType.properties
defaultTeamTypeProperties.features.deviceGroups = true
app.defaultTeamType.properties = defaultTeamTypeProperties
await app.defaultTeamType.save()
token = await createExpertMcpToken(app)
})
after(async function () {
await app.close()
})
it('should list an application\'s device groups through the real route', async function () {
const inject = (options) => app.inject({
...options,
headers: { ...(options.headers || {}), authorization: `Bearer ${token}` }
})
const tool = findTool('platform_list_application_device_groups')
const response = await tool.handler({ applicationId: app.application.hashid }, { inject })
response.statusCode.should.equal(200)
const body = response.json()
body.should.have.property('count', 0)
body.should.have.property('groups')
body.groups.should.be.an.Array()
body.groups.should.have.length(0)
})
it('should return the same response as the application device-groups route for a populated application', async function () {
const inject = (options) => app.inject({
...options,
headers: { ...(options.headers || {}), authorization: `Bearer ${token}` }
})
const application = await app.factory.createApplication({ name: 'mcp-tool-app-device-groups' }, app.team)
await app.factory.createApplicationDeviceGroup({ name: 'mcp-tool-group-1', description: 'group one' }, application)
await app.factory.createApplicationDeviceGroup({ name: 'mcp-tool-group-2', description: 'group two' }, application)
const tool = findTool('platform_list_application_device_groups')
const { routeResponse } = await expectToolMatchesRoute(
inject,
tool,
{ applicationId: application.hashid },
{ method: 'GET', url: `/api/v1/applications/${application.hashid}/device-groups` }
)
const body = routeResponse.json()
body.should.have.property('count', 2)
body.groups.should.have.length(2)
})
it('should return the same response as the team device-groups route for a populated team', async function () {
const inject = (options) => app.inject({
...options,
headers: { ...(options.headers || {}), authorization: `Bearer ${token}` }
})
const application = await app.factory.createApplication({ name: 'mcp-tool-team-device-groups' }, app.team)
await app.factory.createApplicationDeviceGroup({ name: 'mcp-tool-team-group-1', description: 'team group one' }, application)
const tool = findTool('platform_list_team_device_groups')
const { routeResponse } = await expectToolMatchesRoute(
inject,
tool,
{ teamId: app.team.hashid },
{ method: 'GET', url: `/api/v1/teams/${app.team.hashid}/device-groups` }
)
const body = routeResponse.json()
body.should.have.property('count')
body.count.should.be.greaterThanOrEqual(1)
body.groups.should.matchAny(g => g.name === 'mcp-tool-team-group-1')
})
})
})