-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for device management intents (#119)
* feat: add support for device management intents * fix: fix endpoint for intents
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/lib/deviceManagementIntents/deviceManagementIntents.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Client } from '@microsoft/microsoft-graph-client' | ||
import { DeviceManagementIntent } from 'lib/types' | ||
import { mockClient } from '../../../__fixtures__/@microsoft/microsoft-graph-client' | ||
import { DeviceManagementIntents } from './deviceManagementIntents' | ||
|
||
describe('DeviceManagementIntents', () => { | ||
let graphClient: Client | ||
let deviceManagementIntents: DeviceManagementIntents | ||
const intent = { | ||
displayName: 'test', | ||
id: 'test', | ||
} as DeviceManagementIntent | ||
|
||
beforeEach(() => { | ||
graphClient = mockClient() as never as Client | ||
deviceManagementIntents = new DeviceManagementIntents(graphClient) | ||
}) | ||
|
||
it('should get a intent', async () => { | ||
jest.spyOn(graphClient.api(''), 'get').mockResolvedValue(intent) | ||
const result = await deviceManagementIntents.get('') | ||
expect(result).toEqual(intent) | ||
}) | ||
|
||
it('should list all intents', async () => { | ||
jest.spyOn(graphClient.api(''), 'get').mockResolvedValueOnce({ | ||
value: [intent], | ||
'@odata.nextLink': 'next', | ||
}) | ||
jest.spyOn(graphClient.api(''), 'get').mockResolvedValueOnce({ | ||
value: [intent], | ||
}) | ||
|
||
const result = await deviceManagementIntents.list() | ||
expect(result).toEqual([intent, intent]) | ||
}) | ||
|
||
it('should update a intent', async () => { | ||
const postSpy = jest.spyOn(graphClient.api(''), 'patch').mockResolvedValue(intent) | ||
const result = await deviceManagementIntents.update('id', intent) | ||
expect(result).toEqual(intent) | ||
expect(postSpy).toHaveBeenCalledWith(intent) | ||
}) | ||
|
||
it('should delete a intent', async () => { | ||
const spy = jest.spyOn(graphClient, 'api') | ||
jest.spyOn(graphClient.api(''), 'patch') | ||
const result = await deviceManagementIntents.delete('id') | ||
expect(result).toBeUndefined() | ||
expect(spy).toHaveBeenCalledWith('/deviceManagement/intents/id') | ||
}) | ||
|
||
it('should create a intent', async () => { | ||
const apiSpy = jest.spyOn(graphClient, 'api') | ||
const postSpy = jest.spyOn(graphClient.api(''), 'post').mockResolvedValue(intent) | ||
const result = await deviceManagementIntents.create(intent) | ||
expect(result).toEqual(intent) | ||
expect(apiSpy).toHaveBeenCalledWith('/deviceManagement/intents') | ||
expect(postSpy).toHaveBeenCalledWith(intent) | ||
}) | ||
}) |
38 changes: 38 additions & 0 deletions
38
src/lib/deviceManagementIntents/deviceManagementIntents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Client } from '@microsoft/microsoft-graph-client' | ||
import { Group } from '@microsoft/microsoft-graph-types-beta' | ||
import { DeviceManagementIntent } from 'lib/types' | ||
|
||
export class DeviceManagementIntents { | ||
constructor(private readonly graphClient: Client) {} | ||
|
||
async list() { | ||
let res = await this.graphClient.api('/deviceManagement/intents').get() | ||
const intents: Group[] = res.value | ||
while (res['@odata.nextLink']) { | ||
const nextLink = res['@odata.nextLink'].replace('https://graph.microsoft.com/beta', '') | ||
res = await this.graphClient.api(nextLink).get() | ||
const nextIntents = res.value as DeviceManagementIntent[] | ||
intents.push(...nextIntents) | ||
} | ||
return intents | ||
} | ||
|
||
async get(intentId: string): Promise<Group> { | ||
return this.graphClient.api(`/deviceManagement/intents/${intentId}`).get() | ||
} | ||
|
||
async update( | ||
intentId: string, | ||
intent: DeviceManagementIntent, | ||
): Promise<DeviceManagementIntent> { | ||
return this.graphClient.api(`/deviceManagement/intents/${intentId}`).patch(intent) | ||
} | ||
|
||
async delete(intentId: string): Promise<void> { | ||
return this.graphClient.api(`/deviceManagement/intents/${intentId}`).delete() | ||
} | ||
|
||
async create(intent: DeviceManagementIntent): Promise<DeviceManagementIntent> { | ||
return this.graphClient.api('/deviceManagement/intents').post(intent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters