-
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.
Merge pull request #113 from pliancy/feat/device-management-templates
Feat/device management templates
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/lib/deviceManagementTemplates/deviceManagementTemplates.test.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 { mockClient } from '../../../__fixtures__/@microsoft/microsoft-graph-client' | ||
import { Client } from '@microsoft/microsoft-graph-client' | ||
import { DeviceManagementTemplates } from './deviceManagementTemplates' | ||
import { CreateTemplateInstance, DeviceManagementTemplate } from '../types' | ||
|
||
describe('Devices Management Templates', () => { | ||
let graphClient: Client | ||
let deviceManagementTemplates: DeviceManagementTemplates | ||
|
||
const deviceManagementTemplate = { | ||
name: 'test', | ||
'@odata.type': '#microsoft.graph.deviceManagementTemplate', | ||
id: '1', | ||
} | ||
|
||
beforeEach(() => { | ||
graphClient = mockClient() as never as Client | ||
deviceManagementTemplates = new DeviceManagementTemplates(graphClient) | ||
}) | ||
|
||
it('should list device management templates', async () => { | ||
jest.spyOn(graphClient.api(''), 'get').mockResolvedValue({ | ||
value: [deviceManagementTemplate], | ||
}) | ||
const res = await deviceManagementTemplates.list() | ||
expect(res).toEqual([deviceManagementTemplate]) | ||
}) | ||
|
||
it('should get a device management template', async () => { | ||
jest.spyOn(graphClient.api(''), 'get').mockResolvedValue(deviceManagementTemplate) | ||
const res = await deviceManagementTemplates.get('') | ||
expect(res).toEqual(deviceManagementTemplate) | ||
}) | ||
|
||
it('should create a device management template', async () => { | ||
jest.spyOn(graphClient.api(''), 'post').mockResolvedValue(deviceManagementTemplate) | ||
const res = await deviceManagementTemplates.create({} as DeviceManagementTemplate) | ||
expect(res).toEqual(deviceManagementTemplate) | ||
}) | ||
|
||
it('should update a device management template', async () => { | ||
jest.spyOn(graphClient.api(''), 'patch') | ||
const res = await deviceManagementTemplates.update('id', {} as DeviceManagementTemplate) | ||
expect(res).toBeUndefined() | ||
}) | ||
|
||
it('should delete a device management template', async () => { | ||
jest.spyOn(graphClient.api(''), 'delete') | ||
const res = await deviceManagementTemplates.delete('id') | ||
expect(res).toBeUndefined() | ||
}) | ||
|
||
it('should create create an instance ', async () => { | ||
jest.spyOn(graphClient.api(''), 'post').mockResolvedValue(deviceManagementTemplate) | ||
const res = await deviceManagementTemplates.createInstance( | ||
'1', | ||
{} as CreateTemplateInstance, | ||
) | ||
expect(res).toEqual(deviceManagementTemplate) | ||
}) | ||
}) |
43 changes: 43 additions & 0 deletions
43
src/lib/deviceManagementTemplates/deviceManagementTemplates.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,43 @@ | ||
import { Client } from '@microsoft/microsoft-graph-client' | ||
import { CreateTemplateInstance, DeviceManagementIntent, DeviceManagementTemplate } from '../types' | ||
|
||
export class DeviceManagementTemplates { | ||
constructor(private readonly graphClient: Client) {} | ||
|
||
async list() { | ||
let res = await this.graphClient.api('/deviceManagement/templates').get() | ||
const templates: DeviceManagementTemplate[] = 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 nextTemplates = res.value as DeviceManagementTemplate[] | ||
templates.push(...nextTemplates) | ||
} | ||
return templates | ||
} | ||
|
||
async get(id: string): Promise<DeviceManagementTemplate> { | ||
return await this.graphClient.api(`/deviceManagement/templates/${id}`).get() | ||
} | ||
|
||
async create(script: DeviceManagementTemplate): Promise<DeviceManagementTemplate> { | ||
return await this.graphClient.api('/deviceManagement/templates').post(script) | ||
} | ||
|
||
async update(id: string, script: DeviceManagementTemplate): Promise<DeviceManagementTemplate> { | ||
return await this.graphClient.api(`/deviceManagement/templates/${id}`).patch(script) | ||
} | ||
|
||
async delete(id: string): Promise<void> { | ||
await this.graphClient.api(`/deviceManagement/templates/${id}`).delete() | ||
} | ||
|
||
async createInstance( | ||
templateId: string, | ||
instance: CreateTemplateInstance, | ||
): Promise<DeviceManagementIntent> { | ||
return this.graphClient | ||
.api(`/deviceManagement/templates/${templateId}/createInstance`) | ||
.post(instance) | ||
} | ||
} |
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