Skip to content

Commit

Permalink
refactored to have tests for [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaprar committed Mar 18, 2021
1 parent 9970451 commit 62fa3d5
Show file tree
Hide file tree
Showing 33 changed files with 12,488 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.npmrc

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down
7 changes: 7 additions & 0 deletions bin/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/bash
TAG=$1
(
cd package &&
npm login &&
npm publish
)
6 changes: 6 additions & 0 deletions bin/run.tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

(
cd tests/strapi &&
yarn test
)
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json → package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-provider-email-mailtrap",
"version": "3.1.5",
"version": "3.1.0",
"description": "Mailtrap provider for strapi email",
"keywords": [
"email",
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions tests/strapi/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions tests/strapi/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.cache
build
**/node_modules/**
27 changes: 27 additions & 0 deletions tests/strapi/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"parser": "babel-eslint",
"extends": "eslint:recommended",
"env": {
"commonjs": true,
"es6": true,
"node": true,
"browser": false
},
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": false
},
"sourceType": "module"
},
"globals": {
"strapi": true
},
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"no-console": 0,
"quotes": ["error", "single"],
"semi": ["error", "always"]
}
}
114 changes: 114 additions & 0 deletions tests/strapi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
############################
# OS X
############################

.DS_Store
.AppleDouble
.LSOverride
Icon
.Spotlight-V100
.Trashes
._*


############################
# Linux
############################

*~


############################
# Windows
############################

Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp


############################
# Packages
############################

*.7z
*.csv
*.dat
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.com
*.class
*.dll
*.exe
*.o
*.seed
*.so
*.swo
*.swp
*.swn
*.swm
*.out
*.pid


############################
# Logs and databases
############################

.tmp
*.log
*.sql
*.sqlite
*.sqlite3


############################
# Misc.
############################

*#
ssl
.idea
nbproject
public/uploads/*
!public/uploads/.gitkeep

############################
# Node.js
############################

lib-cov
lcov.info
pids
logs
results
node_modules
.node_history

############################
# Tests
############################

testApp
coverage

############################
# Strapi
############################

.env
license.txt
exports
*.cache
build
.strapi-updater.json
3 changes: 3 additions & 0 deletions tests/strapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Strapi application

A quick description of your strapi application
Empty file added tests/strapi/api/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions tests/strapi/api/email/config/routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"routes": [
{
"method": "GET",
"path": "/email",
"handler": "Email.send",
"config": {
}
}]
}
20 changes: 20 additions & 0 deletions tests/strapi/api/email/controllers/Email.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
send: async (ctx) => {
try {
await strapi.plugins['email'].services.email.send({
to: '[email protected]',
from: '[email protected]',
cc: '[email protected]',
bcc: '[email protected]',
replyTo: '[email protected]',
subject: 'Use strapi email provider successfully',
text: 'Hello world!',
html: 'Hello world!',
});
} catch (error) {
strapi.log.error('Error when sending the email.', error);
return ctx.BadRequest('Error when sending the email.');
}
return 'Email sent.'
}
}
10 changes: 10 additions & 0 deletions tests/strapi/api/system/config/routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"routes": [
{
"method": "GET",
"path": "/ping",
"handler": "System.ping",
"config": {
}
}]
}
5 changes: 5 additions & 0 deletions tests/strapi/api/system/controllers/System.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
ping: async (ctx) => {
return 'pong';
}
}
15 changes: 15 additions & 0 deletions tests/strapi/config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'sqlite',
filename: env('DATABASE_FILENAME', '.tmp/data.db'),
},
options: {
useNullAsDefault: true,
},
},
},
});
13 changes: 13 additions & 0 deletions tests/strapi/config/functions/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*
* See more details here: https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#bootstrap
*/

module.exports = () => {};
21 changes: 21 additions & 0 deletions tests/strapi/config/functions/cron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

/**
* Cron config that gives you an opportunity
* to run scheduled jobs.
*
* The cron format consists of:
* [SECOND (optional)] [MINUTE] [HOUR] [DAY OF MONTH] [MONTH OF YEAR] [DAY OF WEEK]
*
* See more details here: https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#cron-tasks
*/

module.exports = {
/**
* Simple example.
* Every monday at 1am.
*/
// '0 1 * * 1': () => {
//
// }
};
5 changes: 5 additions & 0 deletions tests/strapi/config/functions/responses/404.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = async (/* ctx */) => {
// return ctx.notFound('My custom message 404');
};
13 changes: 13 additions & 0 deletions tests/strapi/config/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = ({ env }) => ({
email: {
provider: 'mailtrap',
providerOptions: {
user: env('MAILTRAP_USER', 'default_user'),
password: env('MAILTRAP_PASSWORD', 'default_password')
},
settings: {
defaultFrom: env('MAILTRAP_DEFAULT_FROM', '[email protected]'),
defaultReplyTo: env('MAILTRAP_DEFAULT_REPLY_TO', '[email protected]'),
},
}
});
9 changes: 9 additions & 0 deletions tests/strapi/config/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
admin: {
auth: {
secret: env('ADMIN_JWT_SECRET', '592a657c18b495888a7b5363dd3bb054'),
},
},
});
Empty file.
3 changes: 3 additions & 0 deletions tests/strapi/extensions/users-permissions/config/jwt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
jwtSecret: process.env.JWT_SECRET || '6ed40859-3ca4-4c16-9442-8f9cc9649922'
};
Binary file added tests/strapi/favicon.ico
Binary file not shown.
50 changes: 50 additions & 0 deletions tests/strapi/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "my-project",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi",
"test": "jest --forceExit --detectOpenHandles"
},
"devDependencies": {
"jest": "^26.6.3",
"supertest": "^6.1.3"
},
"dependencies": {
"knex": "0.21.18",
"sqlite3": "5.0.0",
"strapi": "3.1",
"strapi-admin": "3.1",
"strapi-connector-bookshelf": "3.1",
"strapi-plugin-content-manager": "3.1",
"strapi-plugin-content-type-builder": "3.1",
"strapi-plugin-email": "3.1",
"strapi-plugin-upload": "3.1",
"strapi-plugin-users-permissions": "3.1",
"strapi-provider-email-mailtrap": "file:../../package",
"strapi-utils": "3.1"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "fb03fad9-79ea-4233-b2cb-922d0d51f979"
},
"engines": {
"node": ">=10.16.0 <=14.x.x",
"npm": "^6.0.0"
},
"license": "MIT",
"jest": {
"testPathIgnorePatterns": [
"/node_modules/",
".tmp",
".cache"
],
"testEnvironment": "node"
}
}
3 changes: 3 additions & 0 deletions tests/strapi/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# To prevent search engines from seeing the site altogether, uncomment the next two lines:
# User-Agent: *
# Disallow: /
Empty file.
Loading

0 comments on commit 62fa3d5

Please sign in to comment.