Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('should return user not connected', async () => {
mockingoose.User.toReturn(null, 'findOne')
expect(await Text.followText('5c64389cae3ae3695c711e44', '')).toMatchObject(
{
error: {
code: 401,
message: "Cet utilisateur n'est pas connecté"
}
}
)
mockingoose.User.toReturn({ ...userMock, activated: false }, 'findOne')
expect(
await Text.followText('5c64389cae3ae3695c711e44', 'az200J')
).toMatchObject({
error: {
code: 401,
message: "Cet utilisateur n'est pas connecté"
}
test('User is not connected', async () => {
mockingoose.User.toReturn(null, 'findOne')
expect(
await Amend.downVoteAmend('5c64389cae3ae3695c711e44', 'wrongToken')
).toMatchObject({
error: { code: 401, message: "Cet utilisateur n'est pas connecté" }
})
})
test('should return error message account already activated', async () => {
const activatedUser = {
...userMock,
activated: true
}
mockingoose.User.toReturn(activatedUser, 'findOne').reset('find')
expect(
await User.activateUser('4d55a560ea0be764c55dc01a872c8fc8205cf262994c8')
).toMatchObject({
error: {
code: 405,
message: 'Ce compte est déjà activé'
}
})
})
xit('returns 404 if no user', async () => {
const ctx = createTestContext();
mockingoose.User.toReturn(null, 'findOne');
await getFeedRoute(ctx);
expect(ctx.status).toBe(404);
expect(ctx.body).toMatchSnapshot();
});
});
test('should return text already followed', async () => {
mockingoose.User.toReturn(
{ ...userMock, followedTexts: ['5c64389cae3ae3695c711e44'] },
'findOne'
)
mockingoose.Text.toReturn(null, 'findOne')
expect(
await Text.followText('5c64389cae3ae3695c711e44', 'uv65v76v6779b9')
).toMatchObject({
error: { code: 405, message: 'Vous participez déjà à ce texte' }
})
})
xit('returns data', async () => {
const ctx = createTestContext();
const feedRecords = [
{
_id: '5b19146f65bbc725d2069082',
actionType: FeedActions.ENROLL,
courseId: 'course-id',
data: {},
dateTime: 0,
entityType: FeedEntities.User,
userId: 'apalchys',
},
] as IFeedRecordModel[];
mockingoose.User.toReturn({}, 'findOne');
mockingoose.FeedRecord.toReturn(feedRecords, 'find');
await getFeedRoute(ctx);
expect(ctx.status).toBe(200);
expect(ctx.body).toMatchSnapshot();
});
xit('returns data', async () => {
const ctx = createTestContext();
mockingoose.User.toReturn(
{
_id: 'apalchys',
profile: {},
},
'findOne',
);
await getParticipationsRoute(ctx);
expect(ctx.status).toBe(200);
expect(ctx.body).toMatchSnapshot();
});
});
test('should return nothing because it works', async () => {
const notActivatedUser = {
...userMock,
activated: false
}
mockingoose.User.toReturn(notActivatedUser, 'findOne')
mockingoose.User.toReturn(notActivatedUser, 'save')
expect(
await User.activateUser('4d55a560ea0be764c55dc01a872c8fc8205cf262994c8')
).toHaveProperty('data')
})
})
xit('returns data', async () => {
const ctx = createTestContext();
mockingoose.User.toReturn(
{
profile: {
firstName: 'first name',
},
},
'findOne',
);
await getProfileRoute(ctx);
expect(ctx.status).toBe(200);
expect(ctx.body).toMatchSnapshot();
});
firstName: '',
lastName: '',
};
const profileChanges = {
firstName: 'Foo',
lastName: 'Bar',
};
const ctx = createTestContext();
ctx.request.body = profileChanges;
mockingoose.User.toReturn(
{
profile: oldProfile,
},
'findOne',
);
mockingoose.User.toReturn(null, 'save');
await patchProfileRoute(ctx);
expect(ctx.status).toBe(200);
expect(ctx.body.data.firstName).toBe('Foo');
expect(ctx.body).toMatchSnapshot();
});
});