From 3f2c8c6daeb16502870d486e60588e534bc84837 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 2 Mar 2021 12:43:45 +0000 Subject: [PATCH] tests: rather course (but it works) test coverage for session creation. *will fail intentionally* In response to https://github.com/ether/etherpad-lite/issues/4898 --- .../specs/api/httpRouteSessionCreation.js | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/tests/backend/specs/api/httpRouteSessionCreation.js diff --git a/src/tests/backend/specs/api/httpRouteSessionCreation.js b/src/tests/backend/specs/api/httpRouteSessionCreation.js new file mode 100644 index 000000000..c19b3460e --- /dev/null +++ b/src/tests/backend/specs/api/httpRouteSessionCreation.js @@ -0,0 +1,62 @@ +'use strict'; + +const assert = require('assert').strict; +const common = require('../../common'); +const settings = require('../../../../node/utils/Settings'); +const fs = require('fs'); +let agent; + +const shouldCreateSession = [ + '/p/foo', + '/p/foo/export/html', +]; +const shouldNotCreateSession = [ + '/', + '/api/', + '/favicon.ico', + '/locales.json', + '/pluginfw/plugin-definitions.json', + '/static/js/pad.js', + '/stats/', +]; + +const getDatabaseSize = () => { + const dbFile = settings.dbSettings.filename; + const database = fs.readFileSync(settings.dbSettings.filename, 'utf8'); + return database.split('\n').length; +} + +describe(__filename, function () { + before(async function () { agent = await common.init(); }); + + describe('Session Creation on endpoint', function () { + if (settings.dbType !== 'dirty') this.skip; + + this.timeout(100); + + for (const endpoint of shouldNotCreateSession) { + it(endpoint, async function () { + const previousCount = getDatabaseSize(); + await agent.get(endpoint) + .expect(200) + .expect(() => { + const newCount = getDatabaseSize(); + assert(newCount === previousCount); + }) + }); + } + + for (const endpoint of shouldCreateSession) { + const previousCount = getDatabaseSize(); + it(endpoint, async function () { + await agent.get(endpoint) + .expect(200) + .expect(() => { + const newCount = getDatabaseSize(); + assert(newCount > previousCount); + }) + }); + } + + }); +});