Skip to content

Commit

Permalink
test: Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh4 committed Sep 10, 2024
1 parent 2f55c5d commit 9d70eb8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ILyvelyTestingModule } from '@/testing';
import { ProfileVisibilityLevel } from '@lyvely/interface';
//import { ProfileVisibilityLevel } from '@lyvely/interface';
import { buildProfileTest, ProfileTestDataUtils } from '../testing';
import { LyvelyModule } from '@/core';
import { ProfileVisibilityPolicy } from './profile-visibility.policy';
Expand Down Expand Up @@ -36,85 +36,85 @@ describe('ProfileVisibilityPolicy', () => {

describe('canActivate()', () => {
it('owner can see member profile', async () => {
const { owner, profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.Member);
const { owner, profile } = await testData.createSimpleGroup(0); // Member
const context = await profilesService.findProfileContext(owner, profile);
const canSee = await profileVisibilityPolicy.verify(context);
expect(canSee).toEqual(true);
});

it('member can see member profile', async () => {
const { member, profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.Member);
const { member, profile } = await testData.createSimpleGroup(0); // Member
const context = await profilesService.findProfileContext(member, profile);
const canSee = await profileVisibilityPolicy.verify(context);
expect(canSee).toEqual(true);
});

it('user can not see member profile', async () => {
const user = await testData.createUser('guest');
const { profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.Member);
const { profile } = await testData.createSimpleGroup(0); // Member
const context = await profilesService.findProfileContext(user, profile);
const canSee = await profileVisibilityPolicy.verify(context);
expect(canSee).toEqual(false);
});

it('visitor can not see member profile', async () => {
const { profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.Member);
const { profile } = await testData.createSimpleGroup(0); // Member
const canSee = await profileVisibilityPolicy.verify(new ProfileContext({ profile: profile }));
expect(canSee).toEqual(false);
});

it('owner can see protected profile', async () => {
const { owner, profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.User);
const { owner, profile } = await testData.createSimpleGroup(3); // User
const context = await profilesService.findProfileContext(owner, profile);
const canSee = await profileVisibilityPolicy.verify(context);
expect(canSee).toEqual(true);
});

it('member can see protected profile', async () => {
const { member, profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.User);
const { member, profile } = await testData.createSimpleGroup(3); // User
const context = await profilesService.findProfileContext(member, profile);
const canSee = await profileVisibilityPolicy.verify(context);
expect(canSee).toEqual(true);
});

it('user can see protected profile', async () => {
const user = await testData.createUser('guest');
const { profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.User);
const { profile } = await testData.createSimpleGroup(3); // User
const context = await profilesService.findProfileContext(user, profile);
const canSee = await profileVisibilityPolicy.verify(context);
expect(canSee).toEqual(true);
});

it('guest can not see protected profile', async () => {
const { profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.User);
const { profile } = await testData.createSimpleGroup(3); // User
const canSee = await profileVisibilityPolicy.verify(new ProfileContext({ profile: profile }));
expect(canSee).toEqual(false);
});

it('owner can see public profile', async () => {
const { owner, profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.Visitor);
const { owner, profile } = await testData.createSimpleGroup(4); // Visitor
const context = await profilesService.findProfileContext(owner, profile);
const canSee = await profileVisibilityPolicy.verify(context);
expect(canSee).toEqual(true);
});

it('member can see protected profile', async () => {
const { member, profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.Visitor);
const { member, profile } = await testData.createSimpleGroup(4); // Visitor
const context = await profilesService.findProfileContext(member, profile);
const canSee = await profileVisibilityPolicy.verify(context);
expect(canSee).toEqual(true);
});

it('user can see protected profile', async () => {
const user = await testData.createUser('guest');
const { profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.Visitor);
const { profile } = await testData.createSimpleGroup(4); // Visitor
const context = await profilesService.findProfileContext(user, profile);
const canSee = await profileVisibilityPolicy.verify(context);
expect(canSee).toEqual(true);
});

it('guest can not see protected profile', async () => {
const { profile } = await testData.createSimpleGroup(ProfileVisibilityLevel.Visitor);
const { profile } = await testData.createSimpleGroup(4); // Visitor
const canSee = await profileVisibilityPolicy.verify(new ProfileContext({ profile: profile }));
expect(canSee).toEqual(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { buildProfileTest, ContentScoreDao, ContentScoreService } from '@lyvely/
import { ILyvelyTestingModule } from '@lyvely/api';
import { HabitStatisticsService, StatisticAccumulation } from './habit-statistics.service';
import { CalendarInterval } from '@lyvely/dates';
import { HabitValueAggregationService } from "./habit-value-aggregation.service";

describe('HabitDataPointService', () => {
let habitDataPointService: HabitDataPointService;
Expand All @@ -19,6 +20,7 @@ describe('HabitDataPointService', () => {
.plugins([habitITestPlugin])
.providers([
HabitDataPointService,
HabitValueAggregationService,
HabitDataPointDao,
ContentScoreService,
ContentScoreDao,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Habit } from '../schemas';
import { HabitTimeSeriesService } from './habit-time-series.service';
import { ILyvelyTestingModule } from '@lyvely/api';
import { ProtectedProfileContentContext } from '@lyvely/api';
import { HabitValueAggregationService } from "./habit-value-aggregation.service";

describe('HabitTimeSeriesService', () => {
let habitsTimeSeriesService: HabitTimeSeriesService;
Expand All @@ -23,6 +24,7 @@ describe('HabitTimeSeriesService', () => {
.providers([
HabitsDao,
HabitDataPointDao,
HabitValueAggregationService,
HabitTimeSeriesService,
HabitDataPointService,
HabitsService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('TimerDataPointStrategy', () => {
expect(config).toEqual({
min: 20_000,
max: 20_000,
optimal: 20_000,
})
});

Expand Down

0 comments on commit 9d70eb8

Please sign in to comment.