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/licensee select priv purchase #39

Closed
wants to merge 36 commits into from
Closed
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
Prev Previous commit
Next Next commit
add missing files
Dana Stiefel committed Oct 18, 2024
commit 506d589437d9701306fe965060f4fede61506c32
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//
// License.model.spec.ts
// CompactConnect
//
// Created by InspiringApps on 7/8/2024.
//

import { expect } from 'chai';
import { serverDateFormat, displayDateFormat } from '@/app.config';
import {
License,
LicenseOccupation,
LicenseStatus,
LicenseSerializer
} from '@models/License/License.model';
import { Compact, CompactType } from '@models/Compact/Compact.model';
import { State } from '@models/State/State.model';
import i18n from '@/i18n';
import moment from 'moment';

describe('License model', () => {
before(() => {
const { tm: $tm } = i18n.global;

(window as any).Vue = {
config: {
globalProperties: {
$tm,
}
}
};
i18n.global.locale = 'en';
});
it('should create a License with expected defaults', () => {
const license = new License();

// Test field values
expect(license).to.be.an.instanceof(License);
expect(license.id).to.equal(null);
expect(license.compact).to.equal(null);
expect(license.isPrivilege).to.equal(false);
expect(license.issueState).to.be.an.instanceof(State);
expect(license.isHomeState).to.equal(false);
expect(license.issueDate).to.equal(null);
expect(license.renewalDate).to.equal(null);
expect(license.expireDate).to.equal(null);
expect(license.occupation).to.equal(null);
expect(license.statusState).to.equal(LicenseStatus.INACTIVE);
expect(license.statusCompact).to.equal(LicenseStatus.INACTIVE);

// Test methods
expect(license.issueDateDisplay()).to.equal('');
expect(license.renewalDateDisplay()).to.equal('');
expect(license.expireDateDisplay()).to.equal('');
expect(license.isExpired()).to.equal(false);
expect(license.occupationName()).to.equal('');
});
it('should create a License with specific values', () => {
const data = {
id: 'test-id',
compact: new Compact(),
isPrivilege: true,
issueState: new State(),
isHomeState: true,
issueDate: 'test-issueDate',
renewalDate: 'test-renewalDate',
expireDate: 'test-expireDate',
occupation: LicenseOccupation.AUDIOLOGIST,
statusState: LicenseStatus.ACTIVE,
statusCompact: LicenseStatus.ACTIVE,
};
const license = new License(data);

// Test field values
expect(license).to.be.an.instanceof(License);
expect(license.id).to.equal(data.id);
expect(license.compact).to.be.an.instanceof(Compact);
expect(license.isPrivilege).to.equal(data.isPrivilege);
expect(license.issueState).to.be.an.instanceof(State);
expect(license.isHomeState).to.equal(data.isHomeState);
expect(license.issueDate).to.equal(data.issueDate);
expect(license.renewalDate).to.equal(data.renewalDate);
expect(license.expireDate).to.equal(data.expireDate);
expect(license.occupation).to.equal(data.occupation);
expect(license.statusState).to.equal(data.statusState);
expect(license.statusCompact).to.equal(data.statusCompact);

// Test methods
expect(license.issueDateDisplay()).to.equal('Invalid date');
expect(license.renewalDateDisplay()).to.equal('Invalid date');
expect(license.expireDateDisplay()).to.equal('Invalid date');
expect(license.isExpired()).to.equal(false);
expect(license.occupationName()).to.equal('Audiologist');
});
it('should create a License with specific values through serializer', () => {
const data = {
id: 'test-id',
compact: CompactType.ASLP,
type: 'privilege',
jurisdiction: 'al',
dateOfIssuance: moment().format(serverDateFormat),
dateOfRenewal: moment().format(serverDateFormat),
dateOfExpiration: moment().subtract(1, 'day').format(serverDateFormat),
licenseType: LicenseOccupation.AUDIOLOGIST,
status: LicenseStatus.ACTIVE,
};
const license = LicenseSerializer.fromServer(data);

// Test field values
expect(license).to.be.an.instanceof(License);
expect(license.id).to.equal(data.id);
expect(license.compact).to.be.an.instanceof(Compact);
expect(license.isPrivilege).to.equal(true);
expect(license.issueState).to.be.an.instanceof(State);
expect(license.isHomeState).to.equal(false);
expect(license.issueState.abbrev).to.equal(data.jurisdiction);
expect(license.issueDate).to.equal(data.dateOfIssuance);
expect(license.renewalDate).to.equal(data.dateOfRenewal);
expect(license.expireDate).to.equal(data.dateOfExpiration);
expect(license.occupation).to.equal(data.licenseType);
expect(license.statusState).to.equal(data.status);
expect(license.statusCompact).to.equal(data.status);

// Test methods
expect(license.issueDateDisplay()).to.equal(
moment(data.dateOfIssuance, serverDateFormat).format(displayDateFormat)
);
expect(license.renewalDateDisplay()).to.equal(
moment(data.dateOfRenewal, serverDateFormat).format(displayDateFormat)
);
expect(license.expireDateDisplay()).to.equal(
moment(data.dateOfExpiration, serverDateFormat).format(displayDateFormat)
);
expect(license.isExpired()).to.equal(true);
expect(license.occupationName()).to.equal('Audiologist');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// License.ts
// CompactConnect
//
// Created by InspiringApps on 7/2/2024.
//
import { FeeTypes } from '@/app.config';
import deleteUndefinedProperties from '@models/_helpers';
import { State } from '@models/State/State.model';

// ========================================================
// = Interface =
// ========================================================
export interface InterfacePrivilegePurchaseOption {
jurisdiction?: State | null;
compact?: string | null;
fee?: number | null;
feeType?: FeeTypes | null;
isMilitaryDiscountActive?: boolean;
militaryDiscountType?: FeeTypes | null;
militaryDiscountAmount?: number | null;
isJurisprudenceRequired?: boolean;
}

// ========================================================
// = Model =
// ========================================================
export class PrivilegePurchaseOption implements InterfacePrivilegePurchaseOption {
public $tm?: any = () => [];
public jurisdiction? = null;

constructor(data?: InterfacePrivilegePurchaseOption) {
const cleanDataObject = deleteUndefinedProperties(data);
const global = window as any;
const $tm = global.Vue?.config?.globalProperties?.$tm;

if ($tm) {
this.$tm = $tm;
}

Object.assign(this, cleanDataObject);
}
}

// ========================================================
// = Serializer =
// ========================================================
export class PrivilegePurchaseOptionSerializer {
static fromServer(json: any): PrivilegePurchaseOption {
const purchaseOptionData = {
jurisdiction: new State({ abbrev: json.postalAbbreviation }),
compact: json.compact,
fee: json.jurisdictionFee,
isMilitaryDiscountActive: json?.militaryDiscount?.acvtive === true || false,
militaryDiscountType: json?.militaryDiscount?.discountType || null,
militaryDiscountAmount: json?.militaryDiscount?.discountAmount || null,
isJurisprudenceRequired: json?.jurisprudenceRequirements?.required || false,
};

return new PrivilegePurchaseOption(purchaseOptionData);
}
}