my-project/api/heartbeat/config/routes.json
{
"routes": [{
"method": "GET",
"path": "/heartbeat",
"handler": "heartbeat.index",
"config": {}
}]| { | |
| "routes": [ | |
| { | |
| "method": "GET", | |
| "path": "/hi", | |
| "handler": "Hello.hi", | |
| "config": { | |
| "policies": ["plugins::users-permissions.isAuthenticated"] | |
| } | |
| } |
| const Strapi = require("strapi"); | |
| const http = require("http"); | |
| let instance; | |
| jest.setTimeout(30000); | |
| /** | |
| * Setups strapi for futher testing | |
| */ | |
| async function setupStrapi() { |
| /** | |
| * Default data that factory use | |
| */ | |
| const defaultData = { | |
| password: "1234Abc", | |
| provider: "local", | |
| confirmed: true, | |
| }; | |
| /** | |
| * Returns random username object for user creation |
| image: node:alpine | |
| test: | |
| stage: test | |
| image: node:alpine | |
| before_script: | |
| - npm install | |
| script: | |
| - npm run test-ci | |
| artifacts: |
| const request = require("supertest"); | |
| // function from gist file | |
| const { setupStrapi } = require("./helpers/strapi"); | |
| // We're setting timeout because sometimes bootstrap can take 5-7 seconds (big apps) | |
| jest.setTimeout(10000); | |
| let app; // this is instance of the the strapi | |
| beforeAll(async () => { |
my-project/api/heartbeat/config/routes.json
{
"routes": [{
"method": "GET",
"path": "/heartbeat",
"handler": "heartbeat.index",
"config": {}
}]| const fs = require("fs"); | |
| const Strapi = require("strapi"); | |
| let instance; | |
| async function setupStrapi(entryNamesToOpen) { | |
| if (!instance) { | |
| //delete test database if exists | |
| const testDataBase = `${__dirname}/../../.tmp/test.db`; | |
| if (fs.existsSync(testDataBase)) { |
| { | |
| "defaultConnection": "default", | |
| "connections": { | |
| "default": { | |
| "connector": "bookshelf", | |
| "settings": { | |
| "client": "sqlite", | |
| "filename": ".tmp/test.db", | |
| "host": "${process.env.DATABASE_HOST || '127.0.0.1'}", | |
| "port": "${process.env.DATABASE_PORT || 27017}", |
| /** Runs the application */ | |
| // INPUT_FILE is a path to json file with input_vars | |
| // TARGET_LANG is langauge code that input_vars should be translated to | |
| // process.env.GKEY is Google API Key generated by `gcloud auth application-default print-access-token` | |
| getJSON(INPUT_FILE) // get data from input file | |
| .then(input_vars => convertToArray(input_vars)) // convert data from object to array | |
| .then(input_arr =>processTranslation(input_arr, TARGET_LANG, process.env.GKEY)) // process the whole array | |
| .then(transl_arr => convertToObject(transl_arr)) // convert data from array to object |
| /** | |
| * Get json from local machine | |
| * @param {String} filename on local machine | |
| * @returns {Promise} resolved object is JSON | |
| */ | |
| const getJSON = filename => { | |
| return new Promise((resolve, reject) => { | |
| fs.readFile(filename, (err, data) => { | |
| if (err) { | |
| reject(err); |