lookback / meteor-emails

Improved Meteor emails with templating, previews and automated CSS/SCSS inlining.

Home Page:https://atmospherejs.com/lookback/emails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Templates not found

sean-stanley opened this issue · comments

Hi,

I know the readme and example are supposed to help me not have this problem, but despite trying to follow them very closely I still ended up with a strange bug where my templates aren't being found.
I called console.log just before Mailer.init to see what my Templates variable actually was. Templates and Mailer.init are defined in the same .coffee file by the way.

{ 
  invoiceEmail: { path: 'invoice/invoice-email.html', name: 'invoiceEmail' },
  confirmOrderEmail: { path: 'order/confirmation-email.html', name: 'confirmOrderEmail' },
  subscriptionConfirmation: { path: 'order/subscription-confirmation-email.html', name: 'subscriptionConfirmation' },
  hubReminder: { path: 'hub/hub-reminder.html', name: 'hubReminder' } 
}

I didn't actually define any name properties on my definitions. I assume that must be Mailer doing something in the background?

Anyway, my integration test calls Mailer.render('invoiceEmail', invoice) and throws this error.

Error: Could not find template: invoiceEmail [500]

the path for invoiceEmail is private/invoice/invoice-email.html and I had this working only two days ago. I'm still trying to determine if this happened because of something I did or something that was changed in meteor-emails.

Cheers,

An update,

In your code, this is where I have the error being tripped.

tmpl = Template[templateName]

if not tmpl
      throw new Meteor.Error 500, 'Could not find template: '+templateName

This runs after compile so the proble is not my paths but that the template is not being properly registered to Template.invoiceEmail. I will look for conflicts in my code and post any findings here.

Hey @sean-stanley!

Thanks for investigating. Let me know if you find any issues in the package.

Hi,

So I made a new project and copied in just my server code and tried sending emails and it worked as expected.

So I tried sending an email outside of my test folder (testing with velocity and sanjo:jasmine) and sure enough the message was logged to the console.

If there is an issue it lies in velocity or sanjo:jasmine not being able to or no longer being able to read the templates from the private folder. The Template fails to render because the mirror instance run by Kadira cannot be found. I'm not sure if I should open an issue with Kadira for this or maybe there is something that can be done in your package to help tests find email templates.

The stange thing was I actually tried a few different ways of copying my email templates into the tests directory but they were still never found by Velocity.

I am still quite new to TDD but giving it a good shot. Things like this though frustrate me because my actual code works just I can't run tests on it.

Any thoughts? I'm happy to close the issue if there is nothing that can be done from this end of things.

Did you check out the section about setting BUNDLE_PATH when deployed? Might be of help. Sadly, I have no experience with Kadira Jasmine. What is it? Tried googling it, but it would just yield results on various porn stars ... -.-

Things like this though frustrate me because my actual code works just I can't run tests on it.

Yeah, I feel the same. Testing in Meteor is generally still a pain, since it's such an integrated system to spin up each time – there are very few separate modules.

Always add "meteor" to search query that helps filter out the unwanted naked jasmine's.

I got the package name wrong. Kadira is for stats on the site and they also make flow-router, a new client-only meteor router. They are connected to or are meteorhacks if you've seen any of their packages. I thought the meteorhacks people made my testing suite but it's unclear now I double check.

The testing framework is sanjo:jasmine in velocity https://velocity.readme.io/v1.0/docs/getting-started-with-jasmine

I always use kadira and velocity together so it's not surprising I got the names mixed up. I'll edit my original post to use the correct package names.

Yeah, I know both Kadira the tool and Jasmine the test framework :) We use both them internally at Lookback. Just was confused to see them together.

Interesting, so maybe it's worth trying for yourself to send an email in a server-integration test and see if it works.

Because I am using angular js for client and routing it didn't work to test emails with iron router using the route configuration options included in the package.

Interesting, so maybe it's worth trying for yourself to send an email in a server-integration test and see if it works.

True, true. Apparently, the app/package isn't managing to find the HTML templates while being under test. Quite weird – testing locally should work the same as running locally, seen from an env var perspective.

it didn't work to test emails with iron router using the route configuration options included in the package.

Hum, how so?

Well I am using angular-ui router on the client and manage all not defined routes there. Basically, the route is undefined in angular so it executes my 404 code instead of passing the route on to Iron Router to try and handle. I could probably make Iron Router see the routes somehow but I figured getting automatic tests working would be more useful for long-term maintenance of the project anyway so I didn't spend any time trying to get it working.

It's not really a problem, just the routes don't work "out of the box" in my project.

It looks like templates can't be found in the Velocity test environment. I am using mocha and I get the following log messages when the application starts up in the mirror environment. However I have no issues actually sending the emails.

Add route: [previewB11_1] at path /emails/previewbid_received mailer
Add route: [sendB11_1] at path /emails/sendbid_received mailer
(STDERR) Could not read template file: bid_received.html mailer
Add route: [previewDealerNotification] at path /emails/previewdealer_notification mailer
Add route: [sendDealerNotification] at path /emails/senddealer_notification mailer
Add route: [previewReminderAppointment] at path /emails/previewreminder_appointment mailer
(STDERR) Could not read template file: dealer_notification.html mailer
Add route: [sendReminderAppointment] at path /emails/sendreminder_appointment mailer
Add route: [previewReminderAppointmentDealer] at path /emails/previewreminder_appointment_dealer mailer
Add route: [sendReminderAppointmentDealer] at path /emails/sendreminder_appointment_dealer mailer
(STDERR) Could not read template file: reminder_appointment.html mailer
(STDERR) Could not read template file: reminder_appointment_dealer.html mailer

Then when a test runs I get this message.

Mailer.send: { to: 'guest@2wav.com',
subject: 'I've got your bid!',
template: 'B11_1',
data:
{ dealerId: 'ASDF QEWRTY' } }
(STDERR) Could not render email before sending: Could not find template: B11_1 [500] mailer

This issue is deprecated for me now testing is done other ways and SSR rendering lets me preview emails nicely.