From 6390544dde1e8bb632700ccdbdff1a7c7873bbce Mon Sep 17 00:00:00 2001 From: jcamilleri-scottlogic Date: Fri, 10 May 2024 12:07:37 +0100 Subject: [PATCH] Added yml config for Green Metrics Tool and associated test. --- green_metric_tests/greencheck_test.spec.js | 17 +++++ green_metric_tests/package.json | 16 +++++ usage_scenario.yml | 78 ++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 green_metric_tests/greencheck_test.spec.js create mode 100644 green_metric_tests/package.json create mode 100644 usage_scenario.yml diff --git a/green_metric_tests/greencheck_test.spec.js b/green_metric_tests/greencheck_test.spec.js new file mode 100644 index 00000000..b7f286eb --- /dev/null +++ b/green_metric_tests/greencheck_test.spec.js @@ -0,0 +1,17 @@ +const request = require('supertest'); +const expect = require('chai').expect; + +describe('Greencheck API', () => { + it('Has the correct URL property', () => { + request('https://django:8000') + .get('/greencheck/climateaction.tech') + .expect(200) + .expect('Content-Type', 'application/json') + .expect(function(res) { + if (!res.body.hasOwnProperty('url')) throw new Error("Expected 'url' key!"); + }) + .end(function(err, res){ + if (err) throw err; + }) + }); +}); \ No newline at end of file diff --git a/green_metric_tests/package.json b/green_metric_tests/package.json new file mode 100644 index 00000000..49997901 --- /dev/null +++ b/green_metric_tests/package.json @@ -0,0 +1,16 @@ +{ + "name": "green_metric_tests", + "version": "1.0.0", + "description": "Integration tests for the Greencheck API, intended for use with the Green Metrics Tool from Green Code Berlin. (https://www.green-coding.io/projects/green-metrics-tool/)", + "main": "index.js", + "scripts": { + "test": "mocha '**/*.spec.js'" + }, + "author": "James Camilleri", + "license": "SEE LICENSE IN ../LICENCE", + "dependencies": { + "chai": "^4.2.0", + "mocha": "^10.4.0", + "supertest": "^7.0.0" + } + } \ No newline at end of file diff --git a/usage_scenario.yml b/usage_scenario.yml new file mode 100644 index 00000000..dcdae5b1 --- /dev/null +++ b/usage_scenario.yml @@ -0,0 +1,78 @@ +--- +name: Greencheck Test +author: James Camilleri +description: Scenario to test the Greencheck endpoint of the Green Web Foundation Greencheck API + +version: "3.5" + +networks: + greencheck-network: + +services: + mariadb: + image: mariadb:10.3 + ports: + - 3306:3306 + env: + MYSQL_ROOT_PASSWORD: just-for-github-actions + MYSQL_DATABASE: greencheck + networks: + - greencheck-network + + rabbitmq: + image: rabbitmq:3.9 + env: + RABBITMQ_USERNAME: "guest" + RABBITMQ_PASSWORD: "guest" + ports: + - 5672:5672 + options: '--hostname "rmq" --health-cmd "rabbitmqctl status" --health-interval 10s --health-timeout 10s --health-retries 3 --health-start-period 60s' + networks: + - greencheck-network + + django: + depends_on: + - mariadb + build: + context: . + args: + PIPENV_CFG: --dev + command: + - cp -a . . + - python -m pip install --upgrade pipenv wheel + - pipenv install --deploy --dev --verbose + ports: + - "8000:8000" + restart: on-failure + volumes: + - .:/app + stdin_open: true + tty: true + networks: + - greencheck-network + + test-container: + container_name: test-container + image: node + depends_on: django + setup-commands: + - cp ./green_metric_tests/greencheck_test.spec.js . + - cp ./green_metric_tests/package.json . + - npm install + networks: + - greencheck-network + + flow: + - name: Greencheck API Test + container: test-container + commands: + - type: console + command: npm test + note: Starting test + read-notes-stdout: true + - type: console + command: sleep 30 + note: Idling + - type: console + command: npm test + note: Starting test again \ No newline at end of file