Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: application consents and fixes ENG-572 #102

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@
}
},
"dependencies": {
"axios": "1.3.4",
"tslib": "2.5.0"
"axios": "1.6.0",
"tslib": "2.6.2"
},
"description": "",
"devDependencies": {
"@pliancy/eslint-config-ts": "0.1.0",
"@semantic-release/git": "10.0.1",
"@semantic-release/github": "8.0.7",
"@semantic-release/npm": "9.0.2",
"@types/jest": "29.4.0",
"@types/node": "18.14.6",
"@digitalroute/cz-conventional-changelog-for-jira": "8.0.1",
"@pliancy/eslint-config-ts": "1.1.0",
"@pliancy/semantic-release-config-npm": "2.2.0",
"@types/jest": "29.5.7",
"@types/node": "20.8.10",
"commitizen": "4.3.0",
"cz-conventional-changelog": "3.3.0",
"cpy-cli": "5.0.0",
"husky": "8.0.3",
"jest": "29.4.3",
"jest-mock-axios": "4.7.0-beta4",
"jest": "29.7.0",
"jest-mock-axios": "4.7.3",
"npm-run-all": "4.1.5",
"open-cli": "7.2.0",
"pinst": "3.0.0",
"rimraf": "4.3.0",
"semantic-release": "20.1.1",
"ts-jest": "29.0.5",
"ts-node": "10.9.1",
"typescript": "4.9.5"
"rimraf": "5.0.5",
"ts-jest": "29.1.1",
"typescript": "5.2.2"
},
"keywords": [
"microsoft-partnercenter-node",
Expand Down Expand Up @@ -62,7 +60,7 @@
},
"version": "4.0.2",
"volta": {
"node": "18.14.2",
"node": "20.9.0",
"yarn": "1.22.19"
}
}
24 changes: 24 additions & 0 deletions src/lib/microsoft-partnercenter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MicrosoftPartnerCenter } from './microsoft-partnercenter'
import mockAxios from 'jest-mock-axios'
import { OrderLineItem } from './types/orders.types'
import { ApplicationConsent } from './types'

describe('Microsoft Partner Center', () => {
let partnerCenter: MicrosoftPartnerCenter
Expand Down Expand Up @@ -142,4 +143,27 @@ describe('Microsoft Partner Center', () => {
billingCycle: 'monthly',
})
})

it(' should create an application consent', async () => {
const consent: ApplicationConsent = {
applicationId: '1',
applicationGrants: [
{
scope: '1',
enterpriseApplicationId: '1',
},
],
}
jest.spyOn(mockAxios, 'post').mockResolvedValue({ data: consent })
const result = await partnerCenter.createApplicationConsent('1', consent)
expect(result).toEqual(consent)
expect(mockAxios.post).toHaveBeenCalledWith('/customers/1/applicationconsents', consent)
})

it('should remove an application consent', async () => {
jest.spyOn(mockAxios, 'delete').mockResolvedValue({ data: {} })
const result = await partnerCenter.removeApplicationConsent('1', '1')
expect(result).toBeUndefined()
expect(mockAxios.delete).toHaveBeenCalledWith('/customers/1/applicationconsents/1')
})
})
15 changes: 15 additions & 0 deletions src/lib/microsoft-partnercenter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AxiosInstance } from 'axios'
import { ApplicationConsent } from './types'
import { Availability } from './types/availabilities.types'
import { IPartnerCenterConfig } from './types/common.types'
import { Customer } from './types/customers.types'
Expand Down Expand Up @@ -152,4 +153,18 @@ export class MicrosoftPartnerCenter {
const { data } = await this.httpAgent.get(url)
return data.items
}

async createApplicationConsent(
customerId: string,
applicationConsent: ApplicationConsent,
): Promise<Subscription> {
const url = `/customers/${customerId}/applicationconsents`
const { data } = await this.httpAgent.post(url, applicationConsent)
return data
}

async removeApplicationConsent(customerId: string, applicationConsentId: string) {
const url = `/customers/${customerId}/applicationconsents/${applicationConsentId}`
await this.httpAgent.delete(url)
}
}
9 changes: 9 additions & 0 deletions src/lib/types/application-consent.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface ApplicationConsent {
applicationGrants: ApplicationGrant[]
applicationId: string
}

export interface ApplicationGrant {
scope: string
enterpriseApplicationId: string
}
4 changes: 0 additions & 4 deletions src/lib/types/availabilities.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { BillingPlan, Link } from './common.types'
import { Sku } from './sku.types'

interface Attributes {
objectType: string
}

export interface Availability {
id: string
productId: string
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './subscriptions.types'
export * from './orders.types'
export * from './sku.types'
export * from './availabilities.types'
export * from './application-consent.types'
Loading