|
1 | 1 | // @vitest-environment happy-dom |
2 | 2 |
|
3 | 3 | import { beforeEach, describe, expect, it, vi } from 'vitest'; |
4 | | -import { Location, RobotPart, SharedSecret_State } from '../gen/app/v1/app_pb'; |
| 4 | +import { |
| 5 | + GetRobotPartByNameAndLocationResponse, |
| 6 | + RobotPart, |
| 7 | +} from '../gen/app/v1/app_pb'; |
5 | 8 | import { createRobotClient } from '../robot/dial'; |
6 | 9 | import { AppClient } from './app-client'; |
7 | 10 | import { BillingClient } from './billing-client'; |
@@ -156,98 +159,64 @@ describe('ViamClient', () => { |
156 | 159 | ).rejects.toThrowError('not provided and could not be obtained'); |
157 | 160 | }); |
158 | 161 |
|
159 | | - it('gets location secret if credential is access token -- host', async () => { |
| 162 | + it('gets robot secret if credential is access token -- host', async () => { |
160 | 163 | options = { credentials: testAccessToken }; |
161 | 164 | const client = await subject(); |
162 | 165 |
|
163 | | - const location = new Location({ |
164 | | - auth: { |
165 | | - secrets: [ |
166 | | - { |
167 | | - id: '0', |
168 | | - state: SharedSecret_State.DISABLED, // eslint-disable-line camelcase |
169 | | - secret: 'disabled secret', |
170 | | - }, |
171 | | - { |
172 | | - id: '1', |
173 | | - state: SharedSecret_State.UNSPECIFIED, // eslint-disable-line camelcase |
174 | | - secret: 'unspecified secret', |
175 | | - }, |
176 | | - { |
177 | | - id: '2', |
178 | | - state: SharedSecret_State.ENABLED, // eslint-disable-line camelcase |
179 | | - secret: 'enabled secret', |
180 | | - }, |
181 | | - ], |
182 | | - locationId: 'location', |
183 | | - secret: 'secret', |
184 | | - }, |
| 166 | + const MAIN_PART = new RobotPart({ |
| 167 | + mainPart: true, |
| 168 | + name: 'main-part', |
| 169 | + secret: 'fake-robot-secret', |
185 | 170 | }); |
186 | | - const getLocationMock = vi.fn().mockImplementation(() => location); |
187 | | - AppClient.prototype.getLocation = getLocationMock; |
| 171 | + const partByNameAndLocationResponse = |
| 172 | + new GetRobotPartByNameAndLocationResponse({ |
| 173 | + part: MAIN_PART, |
| 174 | + }); |
| 175 | + const getRobotPartByNameAndLocationMock = vi |
| 176 | + .fn() |
| 177 | + .mockImplementation(() => partByNameAndLocationResponse); |
| 178 | + AppClient.prototype.getRobotPartByNameAndLocation = |
| 179 | + getRobotPartByNameAndLocationMock; |
188 | 180 |
|
189 | 181 | await client.connectToMachine({ |
190 | 182 | host: 'main-part.location.viam.cloud', |
191 | 183 | }); |
192 | | - expect(getLocationMock).toHaveBeenCalledWith('location'); |
| 184 | + expect(getRobotPartByNameAndLocationMock).toHaveBeenCalledWith( |
| 185 | + 'main-part', |
| 186 | + 'location' |
| 187 | + ); |
193 | 188 | expect(createRobotClient).toHaveBeenCalledWith( |
194 | 189 | expect.objectContaining({ |
195 | 190 | credentials: expect.objectContaining({ |
196 | | - type: 'robot-location-secret', |
197 | | - payload: 'enabled secret', |
| 191 | + type: 'robot-secret', |
| 192 | + payload: 'fake-robot-secret', |
198 | 193 | }), |
199 | 194 | }) |
200 | 195 | ); |
201 | 196 | }); |
202 | 197 |
|
203 | | - it('gets location secret if credential is access token -- id', async () => { |
| 198 | + it('gets robot secret if credential is access token -- id', async () => { |
204 | 199 | options = { credentials: testAccessToken }; |
205 | 200 | const client = await subject(); |
206 | 201 |
|
207 | 202 | const MAIN_PART = new RobotPart({ |
208 | 203 | mainPart: true, |
209 | | - locationId: 'location-id', |
210 | 204 | fqdn: 'main-part.fqdn', |
| 205 | + secret: 'fake-robot-secret', |
211 | 206 | }); |
212 | 207 | const robotParts = [MAIN_PART]; |
213 | 208 | const getRobotPartsMock = vi.fn().mockImplementation(() => robotParts); |
214 | 209 | AppClient.prototype.getRobotParts = getRobotPartsMock; |
215 | 210 |
|
216 | | - const location = new Location({ |
217 | | - auth: { |
218 | | - secrets: [ |
219 | | - { |
220 | | - id: '0', |
221 | | - state: SharedSecret_State.DISABLED, // eslint-disable-line camelcase |
222 | | - secret: 'disabled secret', |
223 | | - }, |
224 | | - { |
225 | | - id: '1', |
226 | | - state: SharedSecret_State.UNSPECIFIED, // eslint-disable-line camelcase |
227 | | - secret: 'unspecified secret', |
228 | | - }, |
229 | | - { |
230 | | - id: '2', |
231 | | - state: SharedSecret_State.ENABLED, // eslint-disable-line camelcase |
232 | | - secret: 'enabled secret', |
233 | | - }, |
234 | | - ], |
235 | | - locationId: 'location', |
236 | | - secret: 'secret', |
237 | | - }, |
238 | | - }); |
239 | | - const getLocationMock = vi.fn().mockImplementation(() => location); |
240 | | - AppClient.prototype.getLocation = getLocationMock; |
241 | | - |
242 | 211 | await client.connectToMachine({ |
243 | 212 | id: 'machine-uuid', |
244 | 213 | }); |
245 | | - expect(getLocationMock).toHaveBeenCalledWith('location-id'); |
| 214 | + expect(getRobotPartsMock).toHaveBeenCalledWith('machine-uuid'); |
246 | 215 | expect(createRobotClient).toHaveBeenCalledWith( |
247 | 216 | expect.objectContaining({ |
248 | 217 | credentials: expect.objectContaining({ |
249 | | - type: 'robot-location-secret', |
250 | | - payload: 'enabled secret', |
| 218 | + type: 'robot-secret', |
| 219 | + payload: 'fake-robot-secret', |
251 | 220 | }), |
252 | 221 | }) |
253 | 222 | ); |
|
0 commit comments