Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ng-container *ngIf="sub && !loading">
<app-subscription-status
[organizationSubscriptionResponse]="sub"
[exempt]="userOrg.exemptFromBillingAutomation"
(reinstatementRequested)="reinstate()"
*ngIf="!userOrg.isFreeOrg"
></app-subscription-status>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,50 @@ describe("SubscriptionStatusComponent", () => {
expect(component.status).toBe("incomplete_expired");
});
});

describe("data getter with exempt organization", () => {
it("suppresses callout when organization is exempt and status is past_due", () => {
component.exempt = true;
component.organizationSubscriptionResponse = makeOrgResponse(
makeSubscription({ status: "past_due" }),
);
expect(component.data.callout).toBeUndefined();
expect(component.data.status).toBeDefined();
});

it("suppresses callout when organization is exempt and status is unpaid", () => {
component.exempt = true;
component.organizationSubscriptionResponse = makeOrgResponse(
makeSubscription({ status: "unpaid" }),
);
expect(component.data.callout).toBeUndefined();
expect(component.data.status).toBeDefined();
});

it("suppresses callout when organization is exempt and status is pending_cancellation", () => {
component.exempt = true;
component.organizationSubscriptionResponse = makeOrgResponse(
makeSubscription({ cancelAtEndDate: true }),
);
expect(component.data.callout).toBeUndefined();
expect(component.data.status).toBeDefined();
});

it("suppresses callout when organization is exempt and status is canceled", () => {
component.exempt = true;
component.organizationSubscriptionResponse = makeOrgResponse(
makeSubscription({ status: "canceled" }),
);
expect(component.data.callout).toBeUndefined();
expect(component.data.status).toBeDefined();
});

it("does not suppress callout when organization is not exempt", () => {
component.exempt = false;
component.organizationSubscriptionResponse = makeOrgResponse(
makeSubscription({ status: "past_due" }),
);
expect(component.data.callout).toBeDefined();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export class SubscriptionStatusComponent {
// eslint-disable-next-line @angular-eslint/prefer-signals
@Input({ required: true }) organizationSubscriptionResponse: OrganizationSubscriptionResponse;
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
// eslint-disable-next-line @angular-eslint/prefer-signals
@Input() exempt = false;
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
// eslint-disable-next-line @angular-eslint/prefer-output-emitter-ref
@Output() reinstatementRequested = new EventEmitter<void>();

Expand Down Expand Up @@ -78,6 +81,26 @@ export class SubscriptionStatusComponent {
const subscriptionExpiredDateLabel = this.i18nService.t("subscriptionExpired");
const cancellationDateLabel = this.i18nService.t("cancellationDate");

const result = this.getStatusData(
defaultStatusLabel,
nextChargeDateLabel,
subscriptionExpiredDateLabel,
cancellationDateLabel,
);

if (this.exempt && result?.callout) {
return { ...result, callout: undefined };
}

return result;
}

private getStatusData(
defaultStatusLabel: string,
nextChargeDateLabel: string,
subscriptionExpiredDateLabel: string,
cancellationDateLabel: string,
): ComponentData {
switch (this.status) {
case "free": {
return {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ describe("OrganizationWarningsService", () => {
});
});

it("should return null when organization is exempt", (done) => {
const exemptOrganization = {
...organization,
exemptFromBillingAutomation: true,
} as Organization;

service.getResellerRenewalWarning$(exemptOrganization).subscribe((result) => {
expect(result).toBeNull();
expect(organizationBillingClient.getWarnings).not.toHaveBeenCalled();
done();
});
});

it("should return upcoming warning with correct type and message", (done) => {
const renewalDate = new Date(2024, 11, 31);
const warning = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ export class OrganizationWarningsService {

getResellerRenewalWarning$ = (
organization: Organization,
): Observable<OrganizationResellerRenewalWarning | null> =>
this.getWarning$(organization, (response) => response.resellerRenewal).pipe(
): Observable<OrganizationResellerRenewalWarning | null> => {
if (organization.exemptFromBillingAutomation) {
return of(null);
}
return this.getWarning$(organization, (response) => response.resellerRenewal).pipe(
map((warning) => {
if (!warning) {
return null;
Expand Down Expand Up @@ -143,6 +146,7 @@ export class OrganizationWarningsService {
}
}),
);
};

getTaxIdWarning$ = (organization: Organization): Observable<TaxIdWarningType | null> =>
merge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe("ORGANIZATIONS state", () => {
useDisableSMAdsForUsers: false,
usePhishingBlocker: false,
useMyItems: false,
exemptFromBillingAutomation: false,
},
};
const result = sut.deserializer(JSON.parse(JSON.stringify(expectedResult)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class OrganizationData {
ssoMemberDecryptionType?: MemberDecryptionType;
usePhishingBlocker: boolean;
useMyItems: boolean;
exemptFromBillingAutomation: boolean;

constructor(
response?: ProfileOrganizationResponse,
Expand Down Expand Up @@ -141,6 +142,7 @@ export class OrganizationData {
this.ssoMemberDecryptionType = response.ssoMemberDecryptionType;
this.usePhishingBlocker = response.usePhishingBlocker;
this.useMyItems = response.useMyItems;
this.exemptFromBillingAutomation = response.exemptFromBillingAutomation ?? false;

this.isMember = options.isMember;
this.isProviderUser = options.isProviderUser;
Expand Down
2 changes: 2 additions & 0 deletions libs/common/src/admin-console/models/domain/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class Organization {
ssoMemberDecryptionType?: MemberDecryptionType;
usePhishingBlocker: boolean;
useMyItems: boolean;
exemptFromBillingAutomation: boolean;

constructor(obj?: OrganizationData) {
if (obj == null) {
Expand Down Expand Up @@ -168,6 +169,7 @@ export class Organization {
this.ssoMemberDecryptionType = obj.ssoMemberDecryptionType;
this.usePhishingBlocker = obj.usePhishingBlocker;
this.useMyItems = obj.useMyItems;
this.exemptFromBillingAutomation = obj.exemptFromBillingAutomation ?? false;
}

get canAccess() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class ProfileOrganizationResponse extends BaseResponse {
ssoMemberDecryptionType?: MemberDecryptionType;
usePhishingBlocker: boolean;
useMyItems: boolean;
exemptFromBillingAutomation: boolean;

constructor(response: any) {
super(response);
Expand Down Expand Up @@ -141,5 +142,7 @@ export class ProfileOrganizationResponse extends BaseResponse {
this.ssoMemberDecryptionType = this.getResponseProperty("SsoMemberDecryptionType");
this.usePhishingBlocker = this.getResponseProperty("UsePhishingBlocker") ?? false;
this.useMyItems = this.getResponseProperty("UseMyItems") ?? false;
this.exemptFromBillingAutomation =
this.getResponseProperty("ExemptFromBillingAutomation") ?? false;
}
}
Loading