Skip to content

Instantly share code, notes, and snippets.

@sergtimosh
Last active April 26, 2020 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergtimosh/bca6c0f5f70d5fc76b1c2f024eb283ef to your computer and use it in GitHub Desktop.
Save sergtimosh/bca6c0f5f70d5fc76b1c2f024eb283ef to your computer and use it in GitHub Desktop.
#helper file
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