all repos — caroster @ f23ba3d49ddd49492d4bb06c4a345acf3ec0235c

[Octree] Group carpool to your event https://caroster.io

e2e/test/specs/03-attachments.js (view raw)

 1'use strict'
 2
 3/* global browser, describe, it, expect, uuidv4, BufferEncoding */
 4
 5const config = require('../')
 6const Login = require('../pages/login')
 7const Mail = require('../pages/mail')
 8const assetsDir = browser.config.assetsDir
 9
10const b64DataGIF =
11  'R0lGODlhPAAoAPECAAAAAP///wAAAAAAACH5BAUAAAIALAAAAAA8ACgAQAJihI+Zwe0Po3Sq1o' +
12  'kztvzoDwbdSJbmiaaqGbbTCrjyA9f2jef6Ts6+uPrNYEIZsdg6IkG8pvMJjUqnVOgypLxmstpX' +
13  'sLv9gr2q8UZshnDTjTUbWH7TqvS6/Y7P6/f8vv9vVwAAOw=='
14
15const b64DataJPEG =
16  '/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/7QA0UGhvdG9zaG9wIDMuMA' +
17  'A4QklNBAQAAAAAABccAgUAC2JsdWVpbXAubmV0HAIAAAIABAD/2wCEAAEBAQEBAQEBAQEBAQEB' +
18  'AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ' +
19  'EBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB' +
20  'AQEBAf/AABEIAAIAAwMBEQACEQEDEQH/xABRAAEAAAAAAAAAAAAAAAAAAAAKEAEBAQADAQEAAA' +
21  'AAAAAAAAAGBQQDCAkCBwEBAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAAP/aAAwD' +
22  'AQACEQMRAD8AG8T9NfSMEVMhQvoP3fFiRZ+MTHDifa/95OFSZU5OzRzxkyejv8ciEfhSceSXGj' +
23  'S8eSdLnZc2HDm4M3BxcXwH/9k='
24
25describe('Attachments', () => {
26  if (!assetsDir) return
27
28  it('logs in', () => {
29    Login.open().authenticate(config.user.email, config.user.password)
30  })
31
32  it('sends one', () => {
33    const recipient = uuidv4() + '@example.org'
34    Mail.open().send(recipient, 'One attachment', null, [
35      assetsDir + 'black+white-60x40.gif'
36    ])
37    const mail = browser.latestMailTo(recipient)
38    expect(mail.attachments.length).toBe(1)
39    const attachment = mail.attachments[0]
40    expect(attachment.name).toBe('black+white-60x40.gif')
41    expect(attachment.type).toBe('image/gif')
42    expect(
43      Buffer.from(
44        attachment.Body,
45        /** @type {BufferEncoding} */
46        (attachment.encoding)
47      ).toString('base64')
48    ).toBe(b64DataGIF)
49  })
50
51  it('sends multiple', () => {
52    const recipient = uuidv4() + '@example.org'
53    Mail.open().send(recipient, 'Multiple attachments', null, [
54      assetsDir + 'black+white-60x40.gif',
55      assetsDir + 'black+white-3x2.jpg'
56    ])
57    const mail = browser.latestMailTo(recipient)
58    expect(mail.attachments.length).toBe(2)
59    const attachment1 = mail.attachments[0]
60    expect(attachment1.name).toBe('black+white-60x40.gif')
61    expect(attachment1.type).toBe('image/gif')
62    expect(
63      Buffer.from(
64        attachment1.Body,
65        /** @type {BufferEncoding} */
66        (attachment1.encoding)
67      ).toString('base64')
68    ).toBe(b64DataGIF)
69    const attachment2 = mail.attachments[1]
70    expect(attachment2.name).toBe('black+white-3x2.jpg')
71    expect(attachment2.type).toBe('image/jpeg')
72    expect(
73      Buffer.from(
74        attachment2.Body,
75        /** @type {BufferEncoding} */
76        (attachment2.encoding)
77      ).toString('base64')
78    ).toBe(b64DataJPEG)
79  })
80})