All I have to do is import my ValidatedMethod into the test, and it crashes with:
Error: A method named ‘walks.writeInitialRecord’ is already defined
import { Meteor } from 'meteor/meteor';
import { Walks } from './collections';
import SimpleSchema from 'simpl-schema';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
export const writeInitialRecordMethod = new ValidatedMethod({
name: 'walks.writeInitialRecord',
mixins: [simpleSchemaMixin],
validate: Walks.simpleSchema().validator(),
run({ walkName }) {
return Walks.insert({walkName: walkName});
}
});
Meteor.methods({
[writeInitialRecordMethod.name]: function(args){
writeInitialRecordMethod.validate.call(this, args);
writeInitialRecordMethod.run.call(this, args);
}
});
Here is the test code in a file called first.app-test.js (as you can see there is no code - because all I have to do is import the method, and everything crashes):
import chai from 'chai';
import { writeInitialRecordMethod } from '../methods';
I have searched for the string ‘walks.writeInitialRecord’ in all of my code and can confirm that this string is only found in one place - in my ValidatedMethod.
Here is the Collections and SimpleSchema stuff:
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
export let Walks = new Mongo.Collection('walks');
Walks.attachBehaviour('timestampable');
export let Schemas = {};
Schemas.Walks = new SimpleSchema({
walkName: {type: String},
});
Walks.attachSchema(Schemas.Walks);
If I write my own code, without ValidatedMethod, it works. Here is my working code:
export const writeInitialRecordMethod = {
name: 'walks.writeInitialRecord',
validate(args) {
new SimpleSchema({
walkName: {type: String},
}).validate(args)
},
run({ walkName }) {
return Walks.insert({walkName: walkName});
}
};
Here is the full error:
W20170810-12:31:11.545(2)? (STDERR) Error: A method named ‘walks.writeInitialRecord’ is already defined
W20170810-12:31:11.545(2)? (STDERR) at packages/ddp-server/livedata_server.js:1592:15
W20170810-12:31:11.546(2)? (STDERR) at Function..each..forEach (packages/underscore.js:147:22)
W20170810-12:31:11.546(2)? (STDERR) at [object Object]..extend.methods (packages/ddp-server/livedata_server.js:1588:7)
W20170810-12:31:11.547(2)? (STDERR) at meteorInstall.imports.server.methods.js (imports/server/methods.js:44:8)
W20170810-12:31:11.547(2)? (STDERR) at fileEvaluate (packages/modules-runtime.js:333:9)
W20170810-12:31:11.548(2)? (STDERR) at require (packages/modules-runtime.js:228:16)
W20170810-12:31:11.548(2)? (STDERR) at meteorInstall.imports.server.test.first.app-test.js (imports/server/test/first.app-test.js:1:105)
W20170810-12:31:11.549(2)? (STDERR) at fileEvaluate (packages/modules-runtime.js:333:9)
W20170810-12:31:11.549(2)? (STDERR) at require (packages/modules-runtime.js:228:16)
W20170810-12:31:11.550(2)? (STDERR) at /private/var/folders/3n/2yry_ys510q6dx0frpznpc4c0000z/T/meteor-test-runnvkqdp/.meteor/local/build/programs/server/app/app.js:764:1