mail-listener2 - How to prevent function from reading wrong emails? - node.js

In my E2E test, I'am using the mail-listener2 to retrieve e-mails. It works fine, except one issue which is driving me crazy and just can't solve it... I have been searching and found different topics and issues regarding this library/package, but just couldn't really find the fix for that.
Following:
I use the function in more than one spec file (register, login, confirmation etc.), and this means that when retrieving the emails, I get from time to time the wrong one. In other words, the function reads the last e-mail in the Inbox which normally belongs to the first test.
Or sometimes the e-mail comes in the Inbox a little bit later that the function is reading them, so it reads the wrong one.
And as I do have an expectation in my it() function:
expect(email.subject).toEqual("subject for e-mail 1");
expect(email['headers'].to).toEqual( userEmail );
therefore the test breaks, and it get following error:
- Expected 'user registration' to equal 'user confirmation'.
- Failed: Cannot read property '1' of null
- Expected 'john.doe#foo.de' to equal 'jane.doe#foo.com'.
- Failed: Cannot read property '1' of null
Is there a way how to force the function reads just the specific email per subject and per user?

Yes, you can find this documented on node-imap (which is used by mail-listener2). Search for the paragraph/bullet on search within that package, here's a snippet to help you find it:
For criteria types that require arguments, use an array instead of just the string criteria type name (e.g. ['FROM', 'foo#bar.com']).
Below that, they list several other search criteria you can use, they have to/from for your user criteria, and subject for that one. So applying this to mail-listener2, you would use this in the searchFilter property:
mailListener = new MailListener({
...(other options),
searchFilter: [['FROM', 'automated#message.com'], ['SUBJECT', 'subject for e-mail 1']],
});
And if you need different search criteria for different tests, you can start a new mail-listener session for each test with the new searchFilter criteria.

Related

Ensure one thing, and then another one if first is false

I have an interface with a list of users and a possibility to add a new one. I want to assert that this user is new (i.e. its email is not already used). So I should check that we have no message pop-up.
checkMailIsNotUsed: () =>
Task.where('#actor checks mail present message is absent',
Ensure.that(UsersList.messageArea, not(isVisible()))),
However this message area could be visible but not with the error messsage I don't expect. So I am looking for, in case above ensure fails, a way to ensure that the text does not include 'already exists'.
Ensure.that(Text.of(UsersList.messageArea), includes('already exists'))),
However if the first 'ensure' is false, everything stops. There is no 'or' or equivalent at the Ensure level. I need to do the second Ensure if first one fails.
How could I do that ?
Thanks in advance.

What makes Outlook/Exchange able to resolve a recipient or not?

I am trying to test whether staff are still employed in the organization.
The best approach I have found so far has to try send them an email.
So, using Outlook, Exchange and Python, I put the email addresses into a new email and try "Resolve" the recipient.
The behavior seems erratic. In most cases, this will produce a result, or "None".
for recipient in msg.Recipients:
try:
exchangeSays = recipient.AddressEntry.GetExchangeUser()
But now in my test case, I have a person john.smith#company.com and whilst the person does exist, is real and present, the entry will not resolve.
I've also noticed that sometimes email addresses resolve to "John Smith" and other recipients will resolve to "john.smith#company.com". I know it's resolved when the name is underlined in the email window.
What's going on here? Some questions:
Is this the best way of checking whether an person is still current?
Am i doing something wrong in my attempt to resolve the recipient?
Firstly, there is no need to create a message and send it - use Application.Session.CreateRecipient / Recipient.Resolve. If Recipient.Resolve returns true, check Recipient.AddressEntry.Type, If it is "EX", the name was resolved to a GAL user. You can however run into problems if you have a contact with the same name in your Contacts folder, and OOM does not allow to resolve against a particular container (e.g. GAL).
Note that Outlook Object Model cannot handle ambiguous names (e.g. "John Smith" will also match "John Smither") - it will simply return an error. If using Redemption is an option (I am its author), it exposes RDOSession.AddressBook.ResolveNameEx, which returns a list of matches.
On the Extended MAPI level (PR_ANR restriction) you can also resolve against a particular container, but OOM does not expose that functionality. In Redemption, you can use RDOSession.AddressBook.GAL.ResolveName/ResolveNameEx. Note however that in this case GAL provider won't resolve an SMTP address of a GAL user (go figure).
Outlook (UI only) also exposes search containers (PR_SEARCH in MAPI, you can see the one exposed by GAL if you click Ctrl + Shift + B to open the address book, then click Tools | Find). You can specify one or more fields to match (e.g. the whole display name or first and last names separately), but OOM, again, does not expose it. In Redemption, you can use RDOSession.Addressbook.GAL.Search:
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set AddrList = Session.Addressbook.GAL
set Search = AddrList.Search
Search.FirstName = "John"
Search.LastName = "Smith"
set AddressEntries = Search.GetResults
for each AddressEntry in AddressEntries
MsgBox AddressEntry.Name
next

How to get a certain (e.g. second or third) mention sent in a message

I've been trying to make a ship command that can either ship the author of the message with a mentioned user, or ship two mentioned users. I can get the 1st mention in a message but I have no idea on how to get the 2nd or even third mention in a message. I tried using:
message.mentions.users.first(2)
splitting the args then slicing them so only the second mention is avalaible, but this gives an "undefined" error when I try to get the username.
Could someone give me a script on exactly how to do it since I can't really get the hang of this
According to the documentation message.mentions.users yields a Collection. So you can just iterate over this collection or convert it to an array and then access the required index:
const userArray = message.mentions.users.array();
console.log(userArray[yourDesiredIndex]);

Netsuite bug when creating customerdeposit record

Im trying to create a customer deposit record in Netsuite using suitescript 1.0.
The original code I had in place which had been working perfectly up until the 2016.2 release broke it.
The update broke it, in that it would override the value submitted in the payment field and instantly make it the full amount of the sales order from the sales order ID. Which is not what we need it to do.
Original Code
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit');
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
After a reply on the Netsuite user group prompted me to use the {recordmode:'dynamic'} attributes I am getting a strange error..
Test Replacement Function which doesnt work
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit',{recordmode:'dynamic'});
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
The error message Im getting now is
Invalid salesorder reference key 1260 for customer .
The thing I dont get is how it is now considered NULL, when the value is hardcoded into this test script after I apply the {recordmode:'dynamic'} value.
Ive tried a wide variety of things, but as I dont have Netsuite support, its proving to be something I simply cant figure out.
Any hints, suggestions would be greatly appreciated as Ive been on this for several days
When you use dynamic the order you set fields makes a difference. So when you set the sales order prior to setting the customer you are actually getting the error message "Invalid salesorder reference key 1260 for customer blank"
What I do is create the customer deposit like:
var depRec = nlapiCreateRecord('customerdeposit', {entity:soRec.getFieldValue('entity'), salesorder:soId});
also setting the undeposited funds flag seems to be required (but not always for some reason) so since you are supplying an account id also do this:
depRec.setFieldValue('undepfunds', 'F');

How to remove the data after user has logged out?

I was following along the example Lending Library app in the book "Packtpub.Getting.Started.with.Meteor.js". It is running at:
http://matloob.lendlib.meteor.com
It works fine, but when a user logs out when one category is open and its items are being displayed, that category and its items remain on the page while the rest is filtered out. On refreshing the page the remaining category is also filtered out.
The publish function is:
Meteor.publish("Categories", function () {
Meteor.flush(); // I added this so it will flush out the remaining data, but :(
return lists.find({owner: this.userId}, {fields: {Category: 1}});
});
It is hard to point out the exact vulnerability withour seeing more code but this is what I could find out: even if not logged in as a user one can set the session variable current_list to an id to get the corresponding list document:
Session.set("current_list",'ZLREaTCPiC6E7ece3')
So I assume that somewhere in your code you publish the details of a list given its id.
At least this would explain why the list remains even after logging out when a category is selected (which in turn means current_list holds an id).
Possibly publishing the list is done using Deps.autorun since the list is immediately published once the session variable is changed.
Maybe you can find that piece of code and post it or just change it so that it also includes a check whether the user is the owner of that list or category.
Consider using the user-status package to listen for users logging out and doing some cleanup on the server as a result:
https://github.com/mizzao/meteor-user-status
Specfically, you can use the following callback:
UserStatus.on "sessionLogout", (advice) ->
console.log(advice.userId + " with session " + advice.sessionId + " logged out")

Resources