Skip to content

Commit

Permalink
graphql-api add license budget
Browse files Browse the repository at this point in the history
  • Loading branch information
bdjonkamla committed Feb 23, 2024
1 parent 681e227 commit cb53ae9
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/graphqlApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 12 additions & 0 deletions src/graphqlApi/types/entities/licenseBudget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type LicenseBudgetType = {
id?: number;
licenseId?: number;
notifications?: LicenseBudgetNotificationType[];
threshold?: number;
type?: string;
};

export type LicenseBudgetNotificationType = {
id?: number;
name?: string;
};
4 changes: 4 additions & 0 deletions src/graphqlApi/types/graphqlApiQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -141,6 +142,7 @@ export enum SelectDataField {
CONTINENT = 'continent',
COUNTRY = 'country',
END_CUSTOMER = 'endCustomer',
LICENSE_BUDGET = 'licenseBudget',
PARTNER = 'partner',
PARTNERTAG = 'partnertag',
SUBSCRIBED_PROGRAM = 'subscribedProgram',
Expand All @@ -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[];
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/graphqlApi/types/graphqlApiSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PartnertagType, boolean>;

Expand Down Expand Up @@ -56,6 +60,15 @@ type MissingFieldsOfOrdersSchema = {
items?: OrderItemsSchema;
};

type MissingFieldsOfLicenseBudgetSchema = {
notifications?: LicenseBudgetNotificationSchema;
};

export type LicenseBudgetSchema = Merge<
Schema<LicenseBudgetType, boolean>,
MissingFieldsOfLicenseBudgetSchema
>;

export type OrderItemsSchema = Merge<
Schema<OrderItemsType, boolean>,
MissingFieldsOfOrderItemSchema
Expand Down Expand Up @@ -90,6 +103,10 @@ export type ContactsSchema = Schema<ContactsType, boolean>;
export type ContinentSchema = Schema<ContinentType, boolean>;
export type CountrySchema = Schema<CountryType, boolean>;
export type ErrorsSchema = Schema<ErrorsType, boolean>;
export type LicenseBudgetNotificationSchema = Schema<
LicenseBudgetNotificationType,
boolean
>;
export type PageSchema = Schema<PageType, boolean>;
export type ProgramSchema = Schema<ProgramType, boolean>;
export type SpecialPriceRateSchema = Schema<SpecialPriceRateType, boolean>;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
46 changes: 46 additions & 0 deletions tests/graphqlApi/graphqlApiClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
EndCustomerType,
ErrorsField,
GraphqlApiClient,
LicenseBudgetType,
PartnerType,
Queries,
SelectAllQueryType,
Expand Down Expand Up @@ -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),
);
});
});
});
42 changes: 42 additions & 0 deletions tests/graphqlApi/mocks/graphqlApiQueries.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }}';

0 comments on commit cb53ae9

Please sign in to comment.