forked from tenshiemi/meteor-contact-form
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontact-form-tests.js
65 lines (55 loc) · 1.87 KB
/
contact-form-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Meteor.settings.contactForm = {
emailTo: '[email protected]'
};
var emailData = {
name: 'Test Name',
email: '[email protected]',
subject: 'Test Subject',
message: 'Test Message'
};
var dataSent = null;
// Email sending stub
Email = {
send: function(data) {
dataSent = data;
}
};
Tinytest.add('Schema', function (test) {
test.instanceOf(Schema, Object);
});
Tinytest.add('Schema - contactForm', function (test) {
test.instanceOf(Schema.contactForm, SimpleSchema);
});
Tinytest.add('Schema - contactForm - name', function (test) {
test.instanceOf(Schema.contactForm._schema.name, Object);
});
Tinytest.add('Schema - contactForm - email', function (test) {
test.instanceOf(Schema.contactForm._schema.email, Object);
});
Tinytest.add('Schema - contactForm - message', function (test) {
test.instanceOf(Schema.contactForm._schema.message, Object);
});
if (Meteor.isServer) {
Tinytest.add('Meteor - methods - sendEmail - exists', function (test) {
test.include(Meteor.server.method_handlers, 'sendEmail');
});
Tinytest.add('Meteor - methods - sendEmail - fails on malformed data', function (test) {
test.throws(function() {
Meteor.call('sendEmail', {something: 'wrong'});
});
});
Tinytest.add('Meteor - methods - sendEmail - sends email successfully', function (test) {
dataSent = null;
Meteor.call('sendEmail', emailData);
test.equal(dataSent.from, emailData.email);
test.equal(dataSent.to, Meteor.settings.contactForm.emailTo);
test.include(dataSent.text, emailData.subject);
test.include(dataSent.text, emailData.message);
});
}
if (Meteor.isClient) {
Tinytest.add('Meteor - templates - contactForm - has a schema helper', function (test) {
test.equal(typeof Template.contactForm.__helpers.get('contactFormSchema'), 'function');
test.equal(Template.contactForm.__helpers.get('contactFormSchema')(), Schema.contactForm);
});
}