-
-
Notifications
You must be signed in to change notification settings - Fork 893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EmailTemplate.js not loading into application #111
Comments
@WhiteFire0 Could you please clarify exact thing you are trying to do?
Do you mean that your app does not insert new document into empty collection of DB? Edit:
|
As you say @tima101 , no new document is inserted into the database. I am able to use the 4-end code to do this successfully, but if I delete the collection and run with my codebase I cannot replicate the result. I should clarify perhaps; by 'breaking changes' to EmailTemplate.js, I mean basic syntactical errors. If I try to execute a function that doesn't exist, it doesn't throw an error. This is not true within the 4-end version of the code, which predictably throws a breaking error. This led me to assume that EmailTemplate.js is not being compiled. |
@WhiteFire0 I see, got it. It has to be code then. I will look into it tomorrow. |
Are there any particular techniques/tools you use when debugging this kind of stack? If you are able to share how you might go about it, perhaps I can learn something in the process and also save your time :) |
@WhiteFire0 Sure! Thanks for asking and being proactive. So main hypothesis that this is code-related not configuration since code inside book does work. I would def-ly add I would also delete collection and restart app to make sure collection is created (meaning Mongoose runs as expected but first document is not created). Problem is either with Mongoose or Could be some typo elsewhere, for example in scripts of |
Ok, found the bug! The problem was as I initially expected; with the code as it stands in the book at the end of This won't occur unless Either way, the only change that needs to be made is the inclusion of the import statement before the screenshots that show the database being updated with the new emailtemplate document, as far as I can tell. |
As a side note, whilst hunting this I found that the |
Not sure that this is true. When user logs in, passport package populates
It would very helpful if you can create repo for me to test, repo in which EmailTemplate.js has all necessary code and document does not get inserted and |
I'm not 100% sure what you mean by adding a proper
Do you mean uploading Given the time zone difference, I have included them in this branch of my repository, in the state described in OP. I have tested it and it does not load the new email template document into mongoDB. |
@WhiteFire0 I suggested committing So when I clone your repo to my machine, I have proper Here is an example of |
@tima101 Got it - I understand you now. I . have reconfigured my root |
As I said in duplicate issue, I already use require instead of import everywhere in my code (to use jest widely), there is no difference to import or to require, you still need to include the module to execute it, node doesn't know anything about any file until it was referenced explicitly. So we still need to import or require EmailTemplate.js to make it work. For example in the User model. As for me, I'd prefer to have some separate init method in EmailTemplate. May be it's better to have some separate setup script, which will be called once on app startup. Imagine I write some unit test for User using clean mongoDB for testing(actually I do). It looks like you get you tools case from a car, and drill start to work right inside the case, even before you opened it. |
@WhiteFire0 I think @YuriGor provided good answer above. Did you try importing I am gonna move testing of email templates in the book's content so it is located after this import is added to User model. I tested importing |
Same issue in Chapter 5 with testing Book/Chapter models - collections and indexes will not be created until we import/reqiure the models somewhere in actually running scripts.
|
Added this blurb to Chapter 4: "Before we test, open
No need to use |
Added following blurb to Chapter 5: "Before we test, open
No need to use Let me know if it looks good to you. Thanks to both of you! |
Yeah, looks good, now that readers, who follow book instructions, will not be confused. |
I strongly disagree that this is an obvious issue to people who are learning how Node behaves. My understanding is that it is an instructional book that aims to work for people with a variety of experience levels. There is nothing obvious about Node architecture to someone who doesn’t know it and the same is true for all programming. |
IMHO this explanation
is enough. |
@WhiteFire0 @YuriGor We try to provide both explanation and link in most cases, so let's keep both. "Obvious" is very relative term. Thanks. |
Thanks for poiting to this issue and for trying to help newbies like me.
I thinks it's a very bad piece of code. Sorry. I've some coworkers doing same things in php with 'imports' only to avoid a small step of setup predeploy, so a useless piece of code is executed at every run. Please, correct me if I have completely misunderstood the behaviours, the goal, the code, or your intention. If, not so possibile, I am right, it's a bad code to show to new entries. |
@realtebo Thank you for your passionate comment. @YuriGor Curiousity question for an expert like you.
Is this possible to achieve? Making code execute in module without referencing that module. Thanks. |
Well, if we need to execute some code from the module - we will need to import it.
So as I got it - @realtebo is talking about the same things. Now we hide this important initialize step behind the chain of dependencies: So change in or re-positioning of any of this chain's link can cause our email notifications to stop working, It's much more clear and safe to reduce this chain to ps now we have no much init tasks, so we can do things simpler |
Right, and remove implicit call from the depth of EmailTemplate |
I'm more to have a deploy script that insert the template |
In the Chapter 4 there is no such thing as "deployment". Running server/app.js in normal situation is equivalent to running post-deployment script: |
@YuriGor Would you like to create a pull request?
The code that needs to be modified is in following subdirectories (
Once code is updated, I will edit book's content to sync it with code. |
Ok, but not instantly
Best, Yuri
…________________________________
From: Tima <[email protected]>
Sent: Thursday, November 15, 2018 8:20:17 PM
To: builderbook/builderbook
Cc: YuriGor; Mention
Subject: Re: [builderbook/builderbook] EmailTemplate.js not loading into application (#111)
Reopened #111<#111>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#111 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AGiyBfZ4zZC8MKuAzfW-O3p-tu_wkQb5ks5uvaJRgaJpZM4Wynk3>.
|
@YuriGor Yeah, this is not urgent at all. Thanks. |
templates.forEach(async (template) => {
if ((await EmailTemplate.find({ name: template.name }).countDocuments()) > 0) {
return;
}
EmailTemplate
.create(template)
.catch((error) => {
logger.error('EmailTemplate insertion error:', error);
});
});
I suggest this code instead: templates.forEach(async (template) => {
try {
await EmailTemplate.updateOne({ name: template.name }, template, { upsert: true });
} catch (error) {
logger.error('EmailTemplate insertion error:', error);
throw error;
}
}); |
@YuriGor Do you still want to do following?
|
Yes, I already did this for chapter 4-end(not committed yet) and tested, it works fine, but before I'll copy this code over other chapters I wanted you to confirm this changes. So now, since you agree, I still need to do this for the rest of chapters, it will take some time to test. |
@YuriGor Thanks! You can do just one chapter, Kelly or I will propagate the change to other chapters. |
Ok, lets finish with #169 and I'll push this one. |
I pushed this changes into separate branch in my repo, so you can start code review even if there is still no PR. |
Note to self: we are waiting for #180 @YuriGor Thank you for creating PR. A small comments: would you consider adding To make life easier for us and reader, do you mind @YuriGor if I simply mention your approach in the text in addition to other solution (importing to |
Hi @tima101, I've got no notification about you mentioned me in your recent comment Now I see you merged my PR, so is your suggestion about try/catch still actual? About second question - it's unclear for me what are you talking about :) |
@YuriGor Thanks for your reply. Got it. Pushed changes to all chapters and main app: Fixed code and text. |
I have got to the end of sub-chapter 'Transactional emails with AWS SES'. On server start, I am unable to get my mLab mongoDB to show evidence of a new email document. If I run the equivalent 4-end code available on the official builderbook repo, mLab gets the document, so I know the error is somewhere in my code.
I have used diff tools to check the difference between my repository and the official 4-end repository on what I thought to be crucial pages: EmailTemplate.js, app.js etc. I cannot find any problematic differences.
I have also wiped all node modules, deleted my yarn.lock/package.json, and re-installed everything with yarn using the package.json available in 4-end, to no avail.
If I make breaking changes to EmailTemplate.js, no errors show at compilation time, leading me to believe that the code isn't being loaded.
My repository can be found here, with the latest commit functioning as described above
I would very much appreciate any assistance on this, as I've dropped quite a few hours into it now. I am sure it is something tiny...
The text was updated successfully, but these errors were encountered: