How to use the mockingoose.User function in mockingoose

To help you get started, we’ve selected a few mockingoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jimmyleray / Emendare / old-server / src / models / text / Text.spec.ts View on Github external
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é"
      }
github jimmyleray / Emendare / old-server / src / models / amend / Amend.spec.ts View on Github external
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é" }
    })
  })
github jimmyleray / Emendare / old-server / src / models / user / User.spec.ts View on Github external
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é'
      }
    })
  })
github rolling-scopes / rsschool-app / app / routes / user / feed.spec.ts View on Github external
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();
    });
});
github jimmyleray / Emendare / old-server / src / models / text / Text.spec.ts View on Github external
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' }
    })
  })
github rolling-scopes / rsschool-app / app / routes / user / feed.spec.ts View on Github external
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();
    });
github rolling-scopes / rsschool-app / app / routes / user / participations.spec.ts View on Github external
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();
    });
});
github jimmyleray / Emendare / old-server / src / models / user / User.spec.ts View on Github external
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')
  })
})
github rolling-scopes / rsschool-app / app / routes / user / profile.spec.ts View on Github external
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();
    });
github rolling-scopes / rsschool-app / app / routes / user / profile.spec.ts View on Github external
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();
    });
});

mockingoose

A Jest package for mocking mongoose models

Unlicense
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis