|
| 1 | +import { Client } from '@microsoft/microsoft-graph-client' |
| 2 | +import { DeviceManagementIntent } from 'lib/types' |
| 3 | +import { mockClient } from '../../../__fixtures__/@microsoft/microsoft-graph-client' |
| 4 | +import { DeviceManagementIntents } from './deviceManagementIntents' |
| 5 | + |
| 6 | +describe('DeviceManagementIntents', () => { |
| 7 | + let graphClient: Client |
| 8 | + let deviceManagementIntents: DeviceManagementIntents |
| 9 | + const intent = { |
| 10 | + displayName: 'test', |
| 11 | + id: 'test', |
| 12 | + } as DeviceManagementIntent |
| 13 | + |
| 14 | + beforeEach(() => { |
| 15 | + graphClient = mockClient() as never as Client |
| 16 | + deviceManagementIntents = new DeviceManagementIntents(graphClient) |
| 17 | + }) |
| 18 | + |
| 19 | + it('should get a intent', async () => { |
| 20 | + jest.spyOn(graphClient.api(''), 'get').mockResolvedValue(intent) |
| 21 | + const result = await deviceManagementIntents.get('') |
| 22 | + expect(result).toEqual(intent) |
| 23 | + }) |
| 24 | + |
| 25 | + it('should list all intents', async () => { |
| 26 | + jest.spyOn(graphClient.api(''), 'get').mockResolvedValueOnce({ |
| 27 | + value: [intent], |
| 28 | + '@odata.nextLink': 'next', |
| 29 | + }) |
| 30 | + jest.spyOn(graphClient.api(''), 'get').mockResolvedValueOnce({ |
| 31 | + value: [intent], |
| 32 | + }) |
| 33 | + |
| 34 | + const result = await deviceManagementIntents.list() |
| 35 | + expect(result).toEqual([intent, intent]) |
| 36 | + }) |
| 37 | + |
| 38 | + it('should update a intent', async () => { |
| 39 | + const postSpy = jest.spyOn(graphClient.api(''), 'patch').mockResolvedValue(intent) |
| 40 | + const result = await deviceManagementIntents.update('id', intent) |
| 41 | + expect(result).toEqual(intent) |
| 42 | + expect(postSpy).toHaveBeenCalledWith(intent) |
| 43 | + }) |
| 44 | + |
| 45 | + it('should delete a intent', async () => { |
| 46 | + const spy = jest.spyOn(graphClient, 'api') |
| 47 | + jest.spyOn(graphClient.api(''), 'patch') |
| 48 | + const result = await deviceManagementIntents.delete('id') |
| 49 | + expect(result).toBeUndefined() |
| 50 | + expect(spy).toHaveBeenCalledWith('/deviceManagement/intents/id') |
| 51 | + }) |
| 52 | + |
| 53 | + it('should create a intent', async () => { |
| 54 | + const apiSpy = jest.spyOn(graphClient, 'api') |
| 55 | + const postSpy = jest.spyOn(graphClient.api(''), 'post').mockResolvedValue(intent) |
| 56 | + const result = await deviceManagementIntents.create(intent) |
| 57 | + expect(result).toEqual(intent) |
| 58 | + expect(apiSpy).toHaveBeenCalledWith('/deviceManagement/intents') |
| 59 | + expect(postSpy).toHaveBeenCalledWith(intent) |
| 60 | + }) |
| 61 | +}) |
0 commit comments