Fixtures for denormalization created on before event in tests instead in Meteor.startup

This commit is contained in:
Berislav 2018-06-12 10:24:53 +02:00
parent 430fdfedbf
commit 0b27dd411a
2 changed files with 21 additions and 21 deletions

34
lib/query/testing/link-cache/fixtures.js Normal file → Executable file
View file

@ -10,7 +10,7 @@ export let groupIds = [];
export let authorIds = [];
export let postIds = [];
Meteor.startup(() => {
export default function createFixtures() {
for (let i = 0; i < CATEGORIES; i++) {
const categoryId = Categories.insert({
name: `Category ${i}`
@ -53,25 +53,25 @@ Meteor.startup(() => {
}
}
});
}
function createPost(authorId) {
const postId = Posts.insert({
title: `Post ${postIds.length}`,
createdAt: new Date(),
});
function createPost(authorId) {
const postId = Posts.insert({
title: `Post ${postIds.length}`,
createdAt: new Date(),
});
postIds.push(postId);
postIds.push(postId);
const authorLink = Posts.getLink(postId, 'author');
authorLink.set(authorId);
const authorLink = Posts.getLink(postId, 'author');
authorLink.set(authorId);
const randomCategoryId = categoryIds[Math.floor(Math.random()*categoryIds.length)];
const randomCategoryId = categoryIds[Math.floor(Math.random()*categoryIds.length)];
const categoriesLink = Posts.getLink(postId, 'categories');
categoriesLink.add(randomCategoryId, {
createdAt: new Date(),
});
const categoriesLink = Posts.getLink(postId, 'categories');
categoriesLink.add(randomCategoryId, {
createdAt: new Date(),
});
return postId;
}
});
return postId;
}

8
lib/query/testing/link-cache/server.test.js Normal file → Executable file
View file

@ -1,4 +1,4 @@
import './fixtures';
import createFixtures from './fixtures';
import { createQuery } from 'meteor/cultofcoders:grapher';
import {
Authors,
@ -9,9 +9,9 @@ import {
} from './collections';
describe('Query Link Denormalization', function() {
// fixtures run in Meteor.startup()
// wait for them to load first
Meteor._sleepForMs(10000);
before(() => {
createFixtures();
});
it('Should not cache work with nested options', function() {
let query = Posts.createQuery({