Skip to content

Commit

Permalink
license conversion sku, update fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bdjonkamla committed Feb 8, 2024
1 parent 5f37e6f commit 3b701fc
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 81 deletions.
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.95.0",
"version": "3.96.0-rc.bdj.1",
"description": "Node.js client for ArrowSphere's public API",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
152 changes: 98 additions & 54 deletions src/licenses/entities/license/conversionSkuResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,99 @@ import { AbstractEntity } from '../../../abstractEntity';

export enum ConversionSkuResultFields {
COLUMN_BILLING_CYCLE = 'billingCycle',
COLUMN_BUY_PRICE = 'buyPrice',
COLUMN_CLASSIFICATION = 'classification',
COLUMN_CURRENCY = 'currency',
COLUMN_END_DATE = 'endDate',
COLUMN_FRIENDLY_NAME = 'friendlyName',
COLUMN_LICENSE_REFERENCE = 'licenseReference',
COLUMN_NAME = 'name',
COLUMN_MIN_QUANTITY = 'minQuantity',
COLUMN_OFFER_NAME = 'offerName',
COLUMN_PRICE_BAND_ARROWSPHERE_SKU = 'priceBandArrowsphereSku',
COLUMN_PARTNER_REF = 'partnerRef',
COLUMN_SEATS = 'seats',
COLUMN_SELL_PRICE = 'sellPrice',
COLUMN_SKU = 'sku',
COLUMN_TERM = 'term',
COLUMN_TOTAL_BUY_PRICE = 'totalBuyPrice',
COLUMN_UOM = 'uom',
COLUMN_VENDOR_CODE = 'vendorCode',
}

export type ConversionSkuExistingResultData = {
[ConversionSkuResultFields.COLUMN_BILLING_CYCLE]: number;
export type ConversionSkuResultData = {
[ConversionSkuResultFields.COLUMN_BUY_PRICE]?: number;
[ConversionSkuResultFields.COLUMN_BILLING_CYCLE]?: number;
[ConversionSkuResultFields.COLUMN_CLASSIFICATION]: string;
[ConversionSkuResultFields.COLUMN_CURRENCY]: string;
[ConversionSkuResultFields.COLUMN_END_DATE]?: string;
[ConversionSkuResultFields.COLUMN_FRIENDLY_NAME]?: string;
[ConversionSkuResultFields.COLUMN_LICENSE_REFERENCE]?: string;
[ConversionSkuResultFields.COLUMN_NAME]: string;
[ConversionSkuResultFields.COLUMN_OFFER_NAME]: string;
[ConversionSkuResultFields.COLUMN_PARTNER_REF]?: string;
[ConversionSkuResultFields.COLUMN_MIN_QUANTITY]?: number;
[ConversionSkuResultFields.COLUMN_PRICE_BAND_ARROWSPHERE_SKU]: string;
[ConversionSkuResultFields.COLUMN_SEATS]?: number;
[ConversionSkuResultFields.COLUMN_SELL_PRICE]?: number;
[ConversionSkuResultFields.COLUMN_SKU]: string;
[ConversionSkuResultFields.COLUMN_TERM]: number;
[ConversionSkuResultFields.COLUMN_TOTAL_BUY_PRICE]: number;
};

export type ConversionSkuResultData = {
[ConversionSkuResultFields.COLUMN_BILLING_CYCLE]: number;
[ConversionSkuResultFields.COLUMN_NAME]: string;
[ConversionSkuResultFields.COLUMN_SKU]: string;
[ConversionSkuResultFields.COLUMN_TERM]: number;
[ConversionSkuResultFields.COLUMN_TOTAL_BUY_PRICE]: number;
[ConversionSkuResultFields.COLUMN_TERM]?: number;
[ConversionSkuResultFields.COLUMN_UOM]: string;
[ConversionSkuResultFields.COLUMN_VENDOR_CODE]: string;
};

export class ConversionSkuResult extends AbstractEntity<ConversionSkuExistingResultData> {
readonly #billingCycle: number;
export class ConversionSkuResult extends AbstractEntity<ConversionSkuResultData> {
readonly #billingCycle?: number;
readonly #buyPrice?: number;
readonly #classification: string;
readonly #currency: string;
readonly #endDate?: string;
readonly #friendlyName?: string;
readonly #licenseReference?: string;
readonly #name: string;
readonly #minQuantity?: number;
readonly #offerName: string;
readonly #priceBandArrowsphereSku: string;
readonly #partnerRef?: string;
readonly #seats?: number;
readonly #sellPrice?: number;
readonly #sku: string;
readonly #term: number;
readonly #totalBuyPrice: number;
readonly #term?: number;
readonly #uom: string;
readonly #vendorCode: string;

public constructor(data: ConversionSkuExistingResultData) {
public constructor(data: ConversionSkuResultData) {
super(data);

this.#billingCycle = data[ConversionSkuResultFields.COLUMN_BILLING_CYCLE];
this.#endDate =
data[ConversionSkuResultFields.COLUMN_END_DATE] ?? undefined;
this.#buyPrice = data[ConversionSkuResultFields.COLUMN_BUY_PRICE];
this.#classification =
data[ConversionSkuResultFields.COLUMN_CLASSIFICATION];
this.#currency = data[ConversionSkuResultFields.COLUMN_CURRENCY];
this.#endDate = data[ConversionSkuResultFields.COLUMN_END_DATE];
this.#friendlyName = data[ConversionSkuResultFields.COLUMN_FRIENDLY_NAME];
this.#licenseReference =
data[ConversionSkuResultFields.COLUMN_LICENSE_REFERENCE] ?? undefined;
this.#name = data[ConversionSkuResultFields.COLUMN_NAME];
this.#seats = data[ConversionSkuResultFields.COLUMN_SEATS] ?? undefined;
this.#minQuantity = data[ConversionSkuResultFields.COLUMN_MIN_QUANTITY];
this.#offerName = data[ConversionSkuResultFields.COLUMN_OFFER_NAME];
this.#priceBandArrowsphereSku =
data[ConversionSkuResultFields.COLUMN_PRICE_BAND_ARROWSPHERE_SKU];
this.#partnerRef = data[ConversionSkuResultFields.COLUMN_PARTNER_REF];
this.#seats = data[ConversionSkuResultFields.COLUMN_SEATS];
this.#sellPrice = data[ConversionSkuResultFields.COLUMN_SELL_PRICE];
this.#sku = data[ConversionSkuResultFields.COLUMN_SKU];
this.#term = data[ConversionSkuResultFields.COLUMN_TERM];
this.#totalBuyPrice =
data[ConversionSkuResultFields.COLUMN_TOTAL_BUY_PRICE];
this.#uom = data[ConversionSkuResultFields.COLUMN_UOM];
this.#vendorCode = data[ConversionSkuResultFields.COLUMN_VENDOR_CODE];
}

public get billingCycle(): number {
public get billingCycle(): number | undefined {
return this.#billingCycle;
}

public get buyPrice(): number | undefined {
return this.#buyPrice;
}

public get classification(): string {
return this.#classification;
}

public get currency(): string {
return this.#currency;
}

public get endDate(): string | undefined {
return this.#endDate;
}
Expand All @@ -72,52 +103,65 @@ export class ConversionSkuResult extends AbstractEntity<ConversionSkuExistingRes
return this.#friendlyName;
}

public get licenseReference(): string | undefined {
return this.#licenseReference;
public get minQuantity(): number | undefined {
return this.#minQuantity;
}

public get name(): string {
return this.#name;
public get offerName(): string {
return this.#offerName;
}

public get priceBandArrowsphereSku(): string {
return this.#priceBandArrowsphereSku;
}

public get partnerRef(): string | undefined {
return this.#partnerRef;
}

public get seats(): number | undefined {
return this.#seats;
}

public get sellPrice(): number | undefined {
return this.#sellPrice;
}

public get sku(): string {
return this.#sku;
}

public get term(): number {
public get term(): number | undefined {
return this.#term;
}

public get totalBuyPrice(): number {
return this.#totalBuyPrice;
public get uom(): string {
return this.#uom;
}

public toJSON(): ConversionSkuExistingResultData | ConversionSkuResultData {
if (!this.licenseReference && !this.seats) {
return {
[ConversionSkuResultFields.COLUMN_BILLING_CYCLE]: this.billingCycle,
[ConversionSkuResultFields.COLUMN_NAME]: this.name,
[ConversionSkuResultFields.COLUMN_SKU]: this.sku,
[ConversionSkuResultFields.COLUMN_TERM]: this.term,
[ConversionSkuResultFields.COLUMN_TOTAL_BUY_PRICE]: this.totalBuyPrice,
};
}
public get vendorCode(): string {
return this.#vendorCode;
}

public toJSON(): ConversionSkuResultData {
return {
[ConversionSkuResultFields.COLUMN_BILLING_CYCLE]: this.billingCycle,
[ConversionSkuResultFields.COLUMN_BUY_PRICE]: this.buyPrice,
[ConversionSkuResultFields.COLUMN_CLASSIFICATION]: this.classification,
[ConversionSkuResultFields.COLUMN_CURRENCY]: this.currency,
[ConversionSkuResultFields.COLUMN_END_DATE]: this.endDate,
[ConversionSkuResultFields.COLUMN_FRIENDLY_NAME]: this.friendlyName,
[ConversionSkuResultFields.COLUMN_LICENSE_REFERENCE]: this
.licenseReference,
[ConversionSkuResultFields.COLUMN_NAME]: this.name,
[ConversionSkuResultFields.COLUMN_MIN_QUANTITY]: this.minQuantity,
[ConversionSkuResultFields.COLUMN_OFFER_NAME]: this.offerName,
[ConversionSkuResultFields.COLUMN_PRICE_BAND_ARROWSPHERE_SKU]: this
.priceBandArrowsphereSku,
[ConversionSkuResultFields.COLUMN_PARTNER_REF]: this.partnerRef,
[ConversionSkuResultFields.COLUMN_SEATS]: this.seats,
[ConversionSkuResultFields.COLUMN_SELL_PRICE]: this.sellPrice,
[ConversionSkuResultFields.COLUMN_SKU]: this.sku,
[ConversionSkuResultFields.COLUMN_TERM]: this.term,
[ConversionSkuResultFields.COLUMN_TOTAL_BUY_PRICE]: this.totalBuyPrice,
[ConversionSkuResultFields.COLUMN_UOM]: this.uom,
[ConversionSkuResultFields.COLUMN_VENDOR_CODE]: this.vendorCode,
};
}
}
8 changes: 2 additions & 6 deletions src/licenses/entities/license/licenseConversionSkuResult.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AbstractEntity } from '../../../abstractEntity';
import {
ConversionSkuExistingResultData,
ConversionSkuResult,
ConversionSkuResultData,
} from './conversionSkuResult';
Expand All @@ -10,9 +9,7 @@ export enum LicenseConversionSkuFields {
}

export type LicenseConversionSkuResultData = {
[LicenseConversionSkuFields.COLUMN_OFFERS]:
| ConversionSkuExistingResultData[]
| ConversionSkuResultData[];
[LicenseConversionSkuFields.COLUMN_OFFERS]: ConversionSkuResultData[];
};

export class LicenseConversionSkuResult extends AbstractEntity<LicenseConversionSkuResultData> {
Expand All @@ -22,8 +19,7 @@ export class LicenseConversionSkuResult extends AbstractEntity<LicenseConversion
super(data);

this.#offers = data[LicenseConversionSkuFields.COLUMN_OFFERS].map(
(result: ConversionSkuExistingResultData) =>
new ConversionSkuResult(result),
(result: ConversionSkuResultData) => new ConversionSkuResult(result),
);
}

Expand Down
54 changes: 43 additions & 11 deletions tests/licenses/entities/licenceConversionSkuResult.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,69 @@ describe('License Conversion Sku', () => {
const input: LicenseConversionSkuResultData = {
offers: [
{
billingCycle: 720,
endDate: '2021-12-31T23:59:59Z',
friendlyName: 'Office 365 E3',
licenseReference: 'XSP5046568',
name: 'Office 365 E3',
buyPrice: 400.2,
classification: 'SaaS',
currency: 'EUR',
endDate: '2023-06-08T10:34:28+00:00',
friendlyName: 'XSP30064|MS-0A-O365-BUSINESS|XSP30070|XSP174',
offerName: 'Office 365 E3',
partnerRef: 'XSP5046568',
priceBandArrowsphereSku:
'XSP30064|MS-0A-O365-BUSINESS|XSP30070|XSP174',
seats: 1,
sku: 'CFQ7TTC0LF8R:0001',
term: 8640,
totalBuyPrice: 400.2,
uom: 'LICENSE',
vendorCode: 'Microsoft',
},
],
};

const result = new LicenseConversionSkuResult(input);
expect(result.toJSON()).to.deep.equal(input);
expect(result.toJSON()).to.deep.equal({
offers: [
{
...input.offers[0],
billingCycle: undefined,
minQuantity: undefined,
sellPrice: undefined,
term: undefined,
},
],
});
});

it('License Conversion Sku', () => {
const input: LicenseConversionSkuResultData = {
offers: [
{
billingCycle: 720,
name: 'Office 365 E3',
classification: 'SaaS',
currency: 'EUR',
offerName: 'Office 365 E3',
minQuantity: 1,
priceBandArrowsphereSku:
'XSP30064|MS-0A-O365-BUSINESS|XSP30070|XSP174',
sellPrice: 410.2,
sku: 'CFQ7TTC0LF8R:0001',
term: 8640,
totalBuyPrice: 400.2,
uom: 'LICENSE',
vendorCode: 'Microsoft',
},
],
};

const result = new LicenseConversionSkuResult(input);
expect(result.toJSON()).to.deep.equal(input);
expect(result.toJSON()).to.deep.equal({
offers: [
{
...input.offers[0],
buyPrice: undefined,
endDate: undefined,
friendlyName: undefined,
partnerRef: undefined,
seats: undefined,
},
],
});
});
});
26 changes: 17 additions & 9 deletions tests/licenses/licenses.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ActionsGetFields,
ActiveSeatsFindResultFields,
BuySellFields,
ConversionSkuExistingResultData,
ConversionSkuResultData,
GetData,
GetLicenseResultData,
Expand Down Expand Up @@ -248,10 +247,16 @@ export const PAYLOAD_LICENSE_HISTORY: GetData<LicenceHistoryResultData> = {
export const CONVERSION_SKU_PAYLOAD: ConversionSkuResultData[] = [
{
billingCycle: 720,
name: 'Office 365 E3',
classification: 'SaaS',
currency: 'EUR',
offerName: 'Office 365 E3',
minQuantity: 1,
priceBandArrowsphereSku: 'XSP30064|MS-0A-O365-BUSINESS|XSP30070|XSP174',
sellPrice: 410.2,
sku: 'CFQ7TTC0LF8R:0001',
term: 8640,
totalBuyPrice: 400.2,
uom: 'LICENSE',
vendorCode: 'Microsoft',
},
];

Expand All @@ -262,17 +267,20 @@ export const PAYLOAD_LICENSE_CONVERSION_SKU: GetData<LicenseConversionSkuResultD
},
};

export const EXISTING_CONVERSION_SKU_PAYLOAD: ConversionSkuExistingResultData[] = [
export const EXISTING_CONVERSION_SKU_PAYLOAD: ConversionSkuResultData[] = [
{
billingCycle: 720,
buyPrice: 400.2,
classification: 'SaaS',
currency: 'EUR',
endDate: '2023-06-08T10:34:28+00:00',
friendlyName: 'XSP30064|MS-0A-O365-BUSINESS|XSP30070|XSP174',
licenseReference: 'XSP5046568',
name: 'Office 365 E3',
offerName: 'Office 365 E3',
partnerRef: 'XSP5046568',
priceBandArrowsphereSku: 'XSP30064|MS-0A-O365-BUSINESS|XSP30070|XSP174',
seats: 1,
sku: 'CFQ7TTC0LF8R:0001',
term: 8640,
totalBuyPrice: 400.2,
uom: 'LICENSE',
vendorCode: 'Microsoft',
},
];

Expand Down

0 comments on commit 3b701fc

Please sign in to comment.