Last active
April 26, 2020 12:06
-
-
Save sergtimosh/bca6c0f5f70d5fc76b1c2f024eb283ef to your computer and use it in GitHub Desktop.
#helper file
This file contains hidden or 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
import { check_inbox, get_messages } from "gmail-tester" | |
import { resolve } from "path" | |
export const mailHelper = { | |
async inboxChecker(from) { | |
const email = await check_inbox( | |
resolve("support/gmail-tester-data/credentials.json"), | |
resolve("support/gmail-tester-data/gmail_token.json"), | |
{ | |
from: from, | |
wait_time_sec: 8, // Poll interval (in seconds) | |
max_wait_time_sec: 32, // Maximum poll interval (in seconds). If reached, return null, indicating the completion of the task(). | |
include_body: true | |
} | |
) | |
return email | |
}, | |
async messageChecker() { | |
const date = Date(Date.now()) - 20000 | |
const email = await get_messages( | |
resolve("support/gmail-tester-data/credentials.json"), | |
resolve("support/gmail-tester-data/gmail_token.json"), | |
{ | |
include_body: true, | |
after: new Date(Date.now() - 120000) // I want to find fresh mail in my inbox | |
} | |
) | |
return email | |
}, | |
async createRandomEmail(randomNum) { | |
return `gmail-tester+${randomNum}@my-company.com` | |
}, | |
getBodyText(html) { | |
const $ = require('cheerio').load(html) | |
$('body').find('br').replaceWith(' ') | |
return $('body').text() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment