Skip to content

Commit

Permalink
fix test to read from mock singleUserState
Browse files Browse the repository at this point in the history
  • Loading branch information
BTreston committed Jan 23, 2025
1 parent 0390f40 commit 0b3bb89
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mock, MockProxy } from "jest-mock-extended";
import { firstValueFrom, of } from "rxjs";

import { FakeStateProvider, mockAccountServiceWith } from "../../../../spec";
import { FakeActiveUserState } from "../../../../spec/fake-state";
import { FakeActiveUserState, FakeSingleUserState } from "../../../../spec/fake-state";
import {
OrganizationUserStatusType,
OrganizationUserType,
Expand All @@ -24,6 +24,7 @@ describe("PolicyService", () => {
let stateProvider: FakeStateProvider;
let organizationService: MockProxy<OrganizationService>;
let activeUserState: FakeActiveUserState<Record<PolicyId, PolicyData>>;
let singleUserState: FakeSingleUserState<Record<PolicyId, PolicyData>>;

let policyService: PolicyService;

Expand All @@ -33,6 +34,7 @@ describe("PolicyService", () => {
organizationService = mock<OrganizationService>();

activeUserState = stateProvider.activeUser.getFake(POLICIES);
singleUserState = stateProvider.singleUser.getFake(activeUserState.userId, POLICIES);

const organizations$ = of([
// User
Expand Down Expand Up @@ -295,7 +297,7 @@ describe("PolicyService", () => {

describe("getAll$", () => {
it("returns the specified PolicyTypes", async () => {
activeUserState.nextState(
singleUserState.nextState(
arrayToRecord([
policyData("policy1", "org4", PolicyType.DisablePersonalVaultExport, true),
policyData("policy2", "org1", PolicyType.ActivateAutofill, true),
Expand All @@ -305,7 +307,7 @@ describe("PolicyService", () => {
);

const result = await firstValueFrom(
policyService.getAll$(PolicyType.DisablePersonalVaultExport),
policyService.getAll$(PolicyType.DisablePersonalVaultExport, activeUserState.userId),
);

expect(result).toEqual([
Expand All @@ -331,7 +333,7 @@ describe("PolicyService", () => {
});

it("does not return disabled policies", async () => {
activeUserState.nextState(
singleUserState.nextState(
arrayToRecord([
policyData("policy1", "org4", PolicyType.DisablePersonalVaultExport, true),
policyData("policy2", "org1", PolicyType.ActivateAutofill, true),
Expand All @@ -341,7 +343,7 @@ describe("PolicyService", () => {
);

const result = await firstValueFrom(
policyService.getAll$(PolicyType.DisablePersonalVaultExport),
policyService.getAll$(PolicyType.DisablePersonalVaultExport, activeUserState.userId),
);

expect(result).toEqual([
Expand All @@ -361,7 +363,7 @@ describe("PolicyService", () => {
});

it("does not return policies that do not apply to the user because the user's role is exempt", async () => {
activeUserState.nextState(
singleUserState.nextState(
arrayToRecord([
policyData("policy1", "org4", PolicyType.DisablePersonalVaultExport, true),
policyData("policy2", "org1", PolicyType.ActivateAutofill, true),
Expand All @@ -371,7 +373,7 @@ describe("PolicyService", () => {
);

const result = await firstValueFrom(
policyService.getAll$(PolicyType.DisablePersonalVaultExport),
policyService.getAll$(PolicyType.DisablePersonalVaultExport, activeUserState.userId),
);

expect(result).toEqual([
Expand All @@ -391,7 +393,7 @@ describe("PolicyService", () => {
});

it("does not return policies for organizations that do not use policies", async () => {
activeUserState.nextState(
singleUserState.nextState(
arrayToRecord([
policyData("policy1", "org4", PolicyType.DisablePersonalVaultExport, true),
policyData("policy2", "org1", PolicyType.ActivateAutofill, true),
Expand All @@ -401,7 +403,7 @@ describe("PolicyService", () => {
);

const result = await firstValueFrom(
policyService.getAll$(PolicyType.DisablePersonalVaultExport),
policyService.getAll$(PolicyType.DisablePersonalVaultExport, activeUserState.userId),
);

expect(result).toEqual([
Expand Down

0 comments on commit 0b3bb89

Please sign in to comment.