Skip to content

Instantly share code, notes, and snippets.

@YuriGor
Last active November 16, 2018 03:09
Show Gist options
  • Save YuriGor/92ea4c21e92e84a15a7e8925c2ec6bcf to your computer and use it in GitHub Desktop.
Save YuriGor/92ea4c21e92e84a15a7e8925c2ec6bcf to your computer and use it in GitHub Desktop.
Example of mongoDb test for builderbook
// /test/server/models/User.test.js
// see https://github.com/vladgolubev/jest-mongodb for preparing in-memory mongoDB for this test.
const mongoose = require('mongoose');
const User = require('../../../server/models/User');
describe('slugify', () => {
beforeAll(async () => {
await mongoose.connect(global.__MONGO_URI__);
console.log('connected');
});
afterAll(async () => {
await mongoose.disconnect();
console.log('disconnected');
});
test('no duplication', async () => {
expect.assertions(1);
await User.remove();
const user = await User.signInOrSignUp({
googleId: 'test1',
email: 'test1@test.ts',
googleToken: { accessToken: 'test1', refreshToken: 'test1' },
displayName: 'Test Name',
avatarUrl: 'test1',
});
expect(user.slug).toBe('test-name');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment