Skip to content

Commit

Permalink
Switched from mailtrap to mailslurper
Browse files Browse the repository at this point in the history
  • Loading branch information
ckulka committed Jan 15, 2024
1 parent 21dd595 commit 7619d94
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 80 deletions.
35 changes: 13 additions & 22 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,24 @@ jobs:
- name: Stop Baikal container
run: docker stop ${{ matrix.dockerfile }}

- name: Build and run MailSlurper
run: |
IMAGE_ID=$(docker build -q 'https://github.com/mailslurper/mailslurper.git#release-1.15.0')
docker run --rm --detach -p 8085:8085 -v ${{ github.workspace }}/cypress/fixtures/mailslurper-config.json:/config.json:ro $IMAGE_ID
- name: Start Baikal container with MSMTP configuration
env:
MSMTPRC: |
# Set default values for all following accounts.
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /dev/stdout
# Confiure mailtrap
account mailtrap
host sandbox.smtp.mailtrap.io
port 25
tls_starttls on
from baikal@example.com
user ${{ secrets.MAILTRAP_USER }}
password ${{ secrets.MAILTRAP_PASSWORD }}
# Set a default account
account default: mailtrap
account default
host mailslurper
port 2500
from baikal@example.com
run: |
docker run --rm -dp 80:80 -e MSMTPRC="$MSMTPRC" --name ${{ matrix.dockerfile }}-msmtp ${{ steps.build-baikal-image.outputs.IMAGE_ID }}
docker cp ${{ github.workspace }}/cypress/fixtures/mail-test.php ${{ matrix.dockerfile }}-msmtp:/var/www/baikal/html/
docker run --rm --detach -p 80:80 -e MSMTPRC="$MSMTPRC" --name ${{ matrix.dockerfile }} ${{ steps.build-baikal-image.outputs.IMAGE_ID }}
docker cp ${{ github.workspace }}/cypress/fixtures/mail-test.php ${{ matrix.dockerfile }}:/var/www/baikal/html/
- name: Run Cypress tests
run: npm run test -- --env MAILTRAP_TOKEN=${{ secrets.MAILTRAP_TOKEN }},MAILTRAP_ACCOUNTID=${{ secrets.MAILTRAP_ACCOUNTID }},MAILTRAP_INBOXID=${{ secrets.MAILTRAP_INBOXID }} --config excludeSpecPattern='[]',screenshotsFolder=cypress/screenshots/mailtrap
- name: Run Cypress tests incl. MSMTP
run: CYPRESS_MSMTP_ENABLED=TRUE npm run test

- name: Archive test results
if: always()
Expand Down
19 changes: 16 additions & 3 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { defineConfig } from "cypress";

export default defineConfig({
let config = {
e2e: {
supportFile: false,
excludeSpecPattern: "**/*.mailtrap.cy.ts",
screenshotsFolder: "cypress/screenshots",
excludeSpecPattern: "",
},
});
reporterOptions: {
mochaFile: "results/my-test-output.txt",
toConsole: true,
},
};

if (process.env.CYPRESS_MSMTP_ENABLED ?? false) {
config.e2e.screenshotsFolder = "cypress/screenshots/msmtp";
} else {
config.e2e.excludeSpecPattern = "**/*.msmtp.cy.ts";
}

export default defineConfig(config as Cypress.ConfigOptions);
54 changes: 0 additions & 54 deletions cypress/e2e/send-mail-with-php.mailtrap.cy.ts

This file was deleted.

20 changes: 20 additions & 0 deletions cypress/e2e/send-mail-with-php.msmtp.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe("Send mail with PHP", () => {
it("Should send an email with PHP", () => {
// Send email through PHP (response of mail-test.php is the email subject)
cy.request("localhost/mail-test.php").then((response) => {
// Verify that the email arrived
cy.request({
url: "localhost:8085/mail",
qs: {
message: response.body,
},
}).should((response) => {
expect(response.body.totalRecords).to.eql(1);
let mail = response.body.mailItems[0];
expect(mail.fromAddress).to.eql("baikal@example.com");
expect(mail.toAddresses).to.eql(["to@example.com"]);
expect(mail.body).to.eql("Email sent with PHP mail()\n");
});
});
});
});
14 changes: 13 additions & 1 deletion cypress/fixtures/mail-test.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<?php
mail("to@example.com", $_REQUEST["subject"], "Email sent with PHP mail()");
try {
$subject = uniqid();
$mail_result = mail("to@example.com", $subject, "Email sent with PHP mail()");

if ($mail_result) {
echo $subject;
} else {
throw new Exception("mail(...) returned false");
}
} catch (\Throwable $th) {
http_response_code(500);
echo $th->getMessage();
}
?>
26 changes: 26 additions & 0 deletions cypress/fixtures/mailslurper-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"wwwAddress": "0.0.0.0",
"wwwPort": 8080,
"wwwPublicURL": "",
"serviceAddress": "0.0.0.0",
"servicePort": 8085,
"servicePublicURL": "",
"smtpAddress": "0.0.0.0",
"smtpPort": 2500,
"dbEngine": "SQLite",
"dbHost": "",
"dbPort": 0,
"dbDatabase": "./mailslurper.db",
"dbUserName": "",
"dbPassword": "",
"maxWorkers": 1000,
"keyFile": "",
"certFile": "",
"adminKeyFile": "",
"adminCertFile": "",
"authenticationScheme": "",
"authSecret": "",
"authSalt": "",
"authTimeoutInMinutes": 120,
"credentials": {}
}

0 comments on commit 7619d94

Please sign in to comment.