From cb53ae989c1c5758ba4589dd2b38ee220aea3f6f Mon Sep 17 00:00:00 2001 From: Bairing Djonkamla Date: Fri, 23 Feb 2024 10:27:34 +0100 Subject: [PATCH] graphql-api add license budget --- package.json | 2 +- src/graphqlApi/index.ts | 1 + .../types/entities/licenseBudget.ts | 12 +++++ src/graphqlApi/types/graphqlApiQueries.ts | 4 ++ src/graphqlApi/types/graphqlApiSchemas.ts | 19 ++++++++ tests/graphqlApi/graphqlApiClient.test.ts | 46 +++++++++++++++++++ .../mocks/graphqlApiQueries.mocks.ts | 42 +++++++++++++++++ 7 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/graphqlApi/types/entities/licenseBudget.ts diff --git a/package.json b/package.json index 74a5d308..cc647b38 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "type": "git", "url": "https://github.com/ArrowSphere/nodejs-api-client.git" }, - "version": "3.99.0", + "version": "3.100.0-rc.bdj.1", "description": "Node.js client for ArrowSphere's public API", "main": "build/index.js", "types": "build/index.d.ts", diff --git a/src/graphqlApi/index.ts b/src/graphqlApi/index.ts index a9663d2d..c08007ca 100644 --- a/src/graphqlApi/index.ts +++ b/src/graphqlApi/index.ts @@ -3,6 +3,7 @@ export * from './types/graphqlApiSchemas'; export * from './types/entities/contact'; export * from './types/entities/company'; export * from './types/entities/country'; +export * from './types/entities/licenseBudget'; export * from './types/entities/order'; export * from './types/entities/partnertag'; export * from './types/entities/subscription'; diff --git a/src/graphqlApi/types/entities/licenseBudget.ts b/src/graphqlApi/types/entities/licenseBudget.ts new file mode 100644 index 00000000..7452f53f --- /dev/null +++ b/src/graphqlApi/types/entities/licenseBudget.ts @@ -0,0 +1,12 @@ +export type LicenseBudgetType = { + id?: number; + licenseId?: number; + notifications?: LicenseBudgetNotificationType[]; + threshold?: number; + type?: string; +}; + +export type LicenseBudgetNotificationType = { + id?: number; + name?: string; +}; diff --git a/src/graphqlApi/types/graphqlApiQueries.ts b/src/graphqlApi/types/graphqlApiQueries.ts index 9b25d24a..07829e87 100644 --- a/src/graphqlApi/types/graphqlApiQueries.ts +++ b/src/graphqlApi/types/graphqlApiQueries.ts @@ -4,6 +4,7 @@ import { PartnerType, } from './entities/company'; import { ContinentType, CountryType } from './entities/country'; +import { LicenseBudgetType } from './entities/licenseBudget'; import { PartnertagType } from './entities/partnertag'; import { SubscribedProgramType } from './entities/program'; import { SubscriptionType } from './entities/subscription'; @@ -141,6 +142,7 @@ export enum SelectDataField { CONTINENT = 'continent', COUNTRY = 'country', END_CUSTOMER = 'endCustomer', + LICENSE_BUDGET = 'licenseBudget', PARTNER = 'partner', PARTNERTAG = 'partnertag', SUBSCRIBED_PROGRAM = 'subscribedProgram', @@ -161,6 +163,7 @@ export type SelectAllResponseDataType = { [SelectDataField.CONTINENT]?: ContinentType[]; [SelectDataField.COUNTRY]?: CountryType[]; [SelectDataField.END_CUSTOMER]?: EndCustomerType[]; + [SelectDataField.LICENSE_BUDGET]?: LicenseBudgetType[]; [SelectDataField.PARTNER]?: PartnerType[]; [SelectDataField.PARTNERTAG]?: PartnertagType[]; [SelectDataField.SUBSCRIBED_PROGRAM]?: SubscribedProgramType[]; @@ -211,6 +214,7 @@ export type SelectOneResponseDataType = { [SelectDataField.CONTINENT]?: ContinentType; [SelectDataField.COUNTRY]?: CountryType; [SelectDataField.END_CUSTOMER]?: EndCustomerType; + [SelectDataField.LICENSE_BUDGET]?: LicenseBudgetType; [SelectDataField.PARTNER]?: PartnerType; [SelectDataField.PARTNERTAG]?: PartnertagType; [SelectDataField.SUBSCRIBED_PROGRAM]?: SubscribedProgramType; diff --git a/src/graphqlApi/types/graphqlApiSchemas.ts b/src/graphqlApi/types/graphqlApiSchemas.ts index 315809fa..622f3200 100644 --- a/src/graphqlApi/types/graphqlApiSchemas.ts +++ b/src/graphqlApi/types/graphqlApiSchemas.ts @@ -22,6 +22,10 @@ import { SpecialPriceRateType } from './entities/specialPriceRate'; import { OrderItemsType, OrdersType } from './entities/order'; import { VendorsType } from './entities/vendor'; import { SubscribedProgramType } from './entities/program'; +import { + LicenseBudgetNotificationType, + LicenseBudgetType, +} from './entities/licenseBudget'; export type PartnertagSchema = Schema; @@ -56,6 +60,15 @@ type MissingFieldsOfOrdersSchema = { items?: OrderItemsSchema; }; +type MissingFieldsOfLicenseBudgetSchema = { + notifications?: LicenseBudgetNotificationSchema; +}; + +export type LicenseBudgetSchema = Merge< + Schema, + MissingFieldsOfLicenseBudgetSchema +>; + export type OrderItemsSchema = Merge< Schema, MissingFieldsOfOrderItemSchema @@ -90,6 +103,10 @@ export type ContactsSchema = Schema; export type ContinentSchema = Schema; export type CountrySchema = Schema; export type ErrorsSchema = Schema; +export type LicenseBudgetNotificationSchema = Schema< + LicenseBudgetNotificationType, + boolean +>; export type PageSchema = Schema; export type ProgramSchema = Schema; export type SpecialPriceRateSchema = Schema; @@ -109,6 +126,7 @@ export type SelectAllResponseDataSchema = { [SelectDataField.CONTINENT]?: ContinentSchema; [SelectDataField.COUNTRY]?: CountrySchema; [SelectDataField.END_CUSTOMER]?: EndCustomerSchema; + [SelectDataField.LICENSE_BUDGET]?: LicenseBudgetSchema; [SelectDataField.PARTNER]?: PartnerSchema; [SelectDataField.PARTNERTAG]?: PartnertagSchema; [SelectDataField.SUBSCRIBED_PROGRAM]?: SubscribedProgramSchema; @@ -126,6 +144,7 @@ export type SelectOneResponseDataSchema = { [SelectDataField.CONTINENT]?: ContinentSchema; [SelectDataField.COUNTRY]?: CountrySchema; [SelectDataField.END_CUSTOMER]?: EndCustomerSchema; + [SelectDataField.LICENSE_BUDGET]?: LicenseBudgetSchema; [SelectDataField.PARTNER]?: PartnerSchema; [SelectDataField.PARTNERTAG]?: PartnertagSchema; [SelectDataField.SUBSCRIBED_PROGRAM]?: SubscribedProgramSchema; diff --git a/tests/graphqlApi/graphqlApiClient.test.ts b/tests/graphqlApi/graphqlApiClient.test.ts index 1f5a7b3e..0e49796b 100644 --- a/tests/graphqlApi/graphqlApiClient.test.ts +++ b/tests/graphqlApi/graphqlApiClient.test.ts @@ -14,6 +14,7 @@ import { EndCustomerType, ErrorsField, GraphqlApiClient, + LicenseBudgetType, PartnerType, Queries, SelectAllQueryType, @@ -460,4 +461,49 @@ describe('GraphqlApiClient', () => { ); }); }); + + describe('findLicenseBudgetByLicenseId', () => { + it('makes a graphql POST request on the specified URL selectOne', async () => { + const licenseBudget: LicenseBudgetType = { + id: 3, + threshold: 6500.0, + type: 'CONSUMED', + notifications: [ + { + id: 37954, + name: '50', + }, + { + id: 37955, + name: '75', + }, + { + id: 37956, + name: '90', + }, + ], + }; + + const expectedResult: SelectOneResultType = { + [Queries.SELECT_ONE]: { + [SelectableField.DATA]: { + [SelectDataField.LICENSE_BUDGET]: licenseBudget, + }, + }, + }; + + graphQLClient.request.resolves(expectedResult); + + const result: SelectOneResultType | null = await client.selectOne( + GraphqlApiQueryMock.SELECT_ONE_LICENSE_BUDGET_QUERY, + ); + + expect(result).to.deep.equals(expectedResult); + + sinon.assert.calledWithExactly( + graphQLClient.request, + sinon.match(GraphqlApiQueryMock.SELECT_ONE_LICENSE_BUDGET_GQL), + ); + }); + }); }); diff --git a/tests/graphqlApi/mocks/graphqlApiQueries.mocks.ts b/tests/graphqlApi/mocks/graphqlApiQueries.mocks.ts index bffd2f8f..4e5c11f1 100644 --- a/tests/graphqlApi/mocks/graphqlApiQueries.mocks.ts +++ b/tests/graphqlApi/mocks/graphqlApiQueries.mocks.ts @@ -570,3 +570,45 @@ export const SELECT_ALL_SUBSCRIBED_PROGRAM_QUERY: SelectAllQueryType = { export const SELECT_ALL_SUBSCRIBED_PROGRAM_GQL = '{selectAll (aggregatorFilter: ["companyId", "internalName"], pagination: {page: 1, perPage: 1000}, sort: [{name: "vendorName", direction: "ASC"}]) { data { subscribedProgram { id availabilityEndedAt availabilityStartedAt companyId internalName subscriptionEndedAt partner { id name address1 city zip phone } program { id internalName name } subscription { id } vendor { id name identifier licenseUrl logoLarge logoSmall logoStandard url } vendorCode vendorName } } errors { code message } pagination { currentPage perPage previous next total totalPage totalPages } }}'; + +export const SELECT_ONE_LICENSE_BUDGET_QUERY: SelectOneQueryType = { + [Queries.SELECT_ONE]: { + __args: { + filters: { + groups: [ + { + items: [ + { + name: 'licenseId', + value: ['123'], + operator: ComparisonOperator.EQUALS, + }, + ], + }, + ], + }, + pagination: { + page: 1, + perPage: 1000, + }, + }, + data: { + licenseBudget: { + id: true, + threshold: true, + type: true, + notifications: { + id: true, + name: true, + }, + }, + }, + errors: { + code: true, + message: true, + }, + }, +}; + +export const SELECT_ONE_LICENSE_BUDGET_GQL = + '{selectOne (filters: {groups: [{items: [{name: "licenseId", value: ["123"], operator: "EQUALS"}]}]}, pagination: {page: 1, perPage: 1000}) { data { licenseBudget { id threshold type notifications { id name } } } errors { code message } }}';