-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
README.md: Added github start badge, formatting, added warning not to…
… share credentials.
- Loading branch information
Showing
1 changed file
with
46 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
# gmail-tester | ||
|
||
<span align="center"> | ||
|
||
[![npm version](https://badge.fury.io/js/gmail-tester.svg)](https://www.npmjs.com/package/gmail-tester) | ||
<span class="badge-npmdownloads"><a href="https://npmjs.org/package/badges" title="View this project on NPM"><img src="https://img.shields.io/npm/dm/badges.svg" alt="NPM downloads" /></a></span> | ||
<span class="badge-npmdownloads"><a href="https://npmjs.org/package/badges" title="View this project on NPM"><img src="https://img.shields.io/npm/dt/badges.svg" alt="NPM downloads" /></a></span> | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
![GitHub stars](https://img.shields.io/github/stars/levz0r/gmail-tester?style=social) | ||
|
||
</span> | ||
|
||
A simple Node.js Gmail client which checks/returns email message(s) straight from any Gmail-powered account (both private and company).<br/> | ||
There are two main functionalities this library provides:<br> | ||
|
@@ -65,6 +70,8 @@ If everything is done right, the last output from the script should be: | |
Congratulations! `gmail-tester` is ready to use. | ||
|
||
⛔️ **Never share or commit `credentials.json` nor `token.json`!!! Whoever has it will have full access to your inbox!** | ||
|
||
# API | ||
|
||
### `get_messages(credentials_json, token_path, options)` | ||
|
@@ -73,12 +80,12 @@ Congratulations! `gmail-tester` is ready to use. | |
`token_path`: Path to OAuth2 token file.<br> | ||
`options`: <br> | ||
|
||
* `from`: String. Filter on the email address of the receiver. | ||
* `to`: String. Filter on the email address of the sender. | ||
* `subject`: String. Filter on the subject of the email. | ||
* `include_body`: boolean. Set to `true` to fetch decoded email bodies. | ||
* `before`: Date. Filter messages received _after_ the specified date. | ||
* `after`: Date. Filter messages received _before_ the specified date. | ||
- `from`: String. Filter on the email address of the receiver. | ||
- `to`: String. Filter on the email address of the sender. | ||
- `subject`: String. Filter on the subject of the email. | ||
- `include_body`: boolean. Set to `true` to fetch decoded email bodies. | ||
- `before`: Date. Filter messages received _after_ the specified date. | ||
- `after`: Date. Filter messages received _before_ the specified date. | ||
|
||
**Returns:** | ||
An array of `email` objects with the following fields:<br> | ||
|
@@ -106,14 +113,14 @@ _Some senders will send you `text/html` content, the others will send you `plain | |
`token_path`: Path to OAuth2 token file.<br> | ||
`options`: <br> | ||
|
||
* `from`: String. Filter on the email address of the receiver. | ||
* `to`: String. Filter on the email address of the sender. | ||
* `subject`: String. Filter on the subject of the email. | ||
* `include_body`: boolean. Set to `true` to fetch decoded email bodies. | ||
* `before`: Date. Filter messages received _after_ the specified date. | ||
* `after`: Date. Filter messages received _before_ the specified date. | ||
* `wait_time_sec`: Integer. Interval between inbox checks (in seconds). _Default: 30 seconds_. | ||
* `max_wait_time_sec`: Integer. Maximum wait time (in seconds). When reached and the email was not found, the script exits. _Default: 60 seconds_. | ||
- `from`: String. Filter on the email address of the receiver. | ||
- `to`: String. Filter on the email address of the sender. | ||
- `subject`: String. Filter on the subject of the email. | ||
- `include_body`: boolean. Set to `true` to fetch decoded email bodies. | ||
- `before`: Date. Filter messages received _after_ the specified date. | ||
- `after`: Date. Filter messages received _before_ the specified date. | ||
- `wait_time_sec`: Integer. Interval between inbox checks (in seconds). _Default: 30 seconds_. | ||
- `max_wait_time_sec`: Integer. Maximum wait time (in seconds). When reached and the email was not found, the script exits. _Default: 60 seconds_. | ||
|
||
**Returns:** | ||
An array of `email` objects with the following fields:<br> | ||
|
@@ -197,32 +204,30 @@ _[examples\cypress\integration\gmail.spec.js](https://github.com/levz0r/gmail-te | |
/// <reference types="Cypress" /> | ||
|
||
describe("Email assertion:", () => { | ||
it("Look for an email with specific subject and link in email body", function() { | ||
it("Look for an email with specific subject and link in email body", function () { | ||
// debugger; //Uncomment for debugger to work... | ||
cy | ||
.task("gmail:get-messages", { | ||
options: { | ||
from: "[email protected]", | ||
subject: "Ubisoft Password Change Request", | ||
include_body: true, | ||
before: new Date(2019, 8, 24, 12, 31, 13), // Before September 24rd, 2019 12:31:13 | ||
after: new Date(2019, 7, 23) // After August 23, 2019 | ||
} | ||
}) | ||
.then(emails => { | ||
assert.isAtLeast( | ||
emails.length, | ||
1, | ||
"Expected to find at least one email, but none were found!" | ||
); | ||
const body = emails[0].body.html; | ||
assert.isTrue( | ||
body.indexOf( | ||
"https://account-uplay.ubi.com/en-GB/action/change-password?genomeid=" | ||
) >= 0, | ||
"Found reset link!" | ||
); | ||
}); | ||
cy.task("gmail:get-messages", { | ||
options: { | ||
from: "[email protected]", | ||
subject: "Ubisoft Password Change Request", | ||
include_body: true, | ||
before: new Date(2019, 8, 24, 12, 31, 13), // Before September 24rd, 2019 12:31:13 | ||
after: new Date(2019, 7, 23) // After August 23, 2019 | ||
} | ||
}).then(emails => { | ||
assert.isAtLeast( | ||
emails.length, | ||
1, | ||
"Expected to find at least one email, but none were found!" | ||
); | ||
const body = emails[0].body.html; | ||
assert.isTrue( | ||
body.indexOf( | ||
"https://account-uplay.ubi.com/en-GB/action/change-password?genomeid=" | ||
) >= 0, | ||
"Found reset link!" | ||
); | ||
}); | ||
}); | ||
}); | ||
``` | ||
|
@@ -233,4 +238,4 @@ Please feel free to contribute to this project. | |
|
||
# Credits | ||
|
||
* Built using [googleapis](https://github.com/googleapis/googleapis). | ||
- Built using [googleapis](https://github.com/googleapis/googleapis). |