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

fix:acceptance-test #859

Merged
merged 11 commits into from
May 9, 2023
79 changes: 79 additions & 0 deletions src/__tests__/acceptance/user-experience.acceptance.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {Client, expect, toJSON} from '@loopback/testlab';
import {MyriadApiApplication} from '../../application';
import {User, UserExperience} from '../../models';
import {NotificationType} from '../../enums';
import {
ExperienceRepository,
UserExperienceRepository,
UserRepository,
NotificationRepository,
} from '../../repositories';
import {
deleteAllRepository,
Expand All @@ -19,8 +21,11 @@ import {
givenUserExperienceRepository,
givenUserInstance,
givenUserRepository,
givenNotification,
givenNotificationRepository,
setupApplication,
} from '../helpers';
import {omit} from 'lodash';

/* eslint-disable @typescript-eslint/no-invalid-this */
/* eslint-disable @typescript-eslint/no-misused-promises*/
Expand All @@ -33,6 +38,7 @@ describe('UserExperienceApplication', function () {
let experienceRepository: ExperienceRepository;
let userRepository: UserRepository;
let userExperienceRepository: UserExperienceRepository;
let notificationRepository: NotificationRepository;
let user: User;

before(async () => {
Expand All @@ -45,6 +51,7 @@ describe('UserExperienceApplication', function () {
userRepository = await givenUserRepository(app);
experienceRepository = await givenExperienceRepository(app);
userExperienceRepository = await givenUserExperienceRepository(app);
notificationRepository = await givenNotificationRepository(app);
});

before(async () => {
Expand Down Expand Up @@ -258,6 +265,78 @@ describe('UserExperienceApplication', function () {
.send()
.expect(422);
});

it('Notification after 5 user has subscribed', async () => {
const experienceCreator = await givenUserInstance(userRepository, {
username: 'alexander',
});
const experience = await givenExperienceInstance(experienceRepository, {
createdBy: experienceCreator.id,
});
const userInstances = await Promise.all([
givenUserInstance(userRepository, {
username: 'alpha',
}),
givenUserInstance(userRepository, {
username: 'beta',
}),
givenUserInstance(userRepository, {
username: 'gamma',
}),
givenUserInstance(userRepository, {
username: 'epsilon',
}),
]);
const userExperienceInstances = await Promise.all([
givenUserExperienceInstance(userExperienceRepository, {
userId: userInstances[0].id,
experienceId: experience.id?.toString(),
subscribed: true,
}),
givenUserExperienceInstance(userExperienceRepository, {
userId: userInstances[1].id,
experienceId: experience.id?.toString(),
subscribed: true,
}),
givenUserExperienceInstance(userExperienceRepository, {
userId: userInstances[2].id,
experienceId: experience.id?.toString(),
subscribed: true,
}),
givenUserExperienceInstance(userExperienceRepository, {
userId: userInstances[3].id,
experienceId: experience.id?.toString(),
subscribed: true,
}),
]);
console.log(userExperienceInstances[0].subscribed);
const userExperience = givenUserExperience({
userId: user.id.toString(),
experienceId: experience.id?.toString(),
subscribed: true,
});
const notifInstances = givenNotification({
type: NotificationType.FOLLOWER_COUNT,
message: '5',
referenceId: experience.id,
});
const notifInstance = Object.assign(omit(notifInstances, ['from']), {
to: experienceCreator.id,
});
const response = await client
.post(`/user/experiences/${experience.id}/subscribe`)
.set('Authorization', `Bearer ${token}`)
.send()
.expect(200);
expect(response.body).to.containDeep(userExperience);

setTimeout(async () => {
const resultNotification = await notificationRepository.find({
where: {type: NotificationType.FOLLOWER_COUNT},
});
expect(resultNotification).to.containDeep(notifInstance);
}, 10000);
});
});

context('when user create a new experience', () => {
Expand Down