initial commit
[squeep-authentication-module] / test / lib / template / login-html.js
diff --git a/test/lib/template/login-html.js b/test/lib/template/login-html.js
new file mode 100644 (file)
index 0000000..4d23911
--- /dev/null
@@ -0,0 +1,74 @@
+/* eslint-env mocha */
+'use strict';
+
+const assert = require('assert');
+const { LoginHTML } = require('../../../lib/template');
+const stubLogger = require('../../stub-logger');
+const lint = require('html-minifier-lint').lint; // eslint-disable-line node/no-unpublished-require
+
+function lintHtml(html) {
+  const result = lint(html);
+  stubLogger.debug('validHtml', '', { result, html });
+  assert(!result);
+}
+
+describe('Template LoginHTML', function () {
+  let ctx, options;
+  beforeEach(function () {
+    ctx = {
+      clientProtocol: 'https',
+    };
+    options = {
+      authenticator: {
+        authnEnabled: ['indieAuth', 'DEBUG_ANY'],
+        secureAuthOnly: true,
+      },
+      manager: {
+        pageTitle: 'page',
+      },
+      dingus: {
+        selfBaseUrl: 'https://example.com/',
+      },
+    };
+  });
+
+  it('covers', function () {
+    const result = LoginHTML(ctx, options);
+    lintHtml(result);
+    assert(result);
+  });
+
+  it('renders errors and additional content', function () {
+    ctx.errors = ['an error', 'another error'];
+    options.manager.logoUrl = 'https://example.com/logo.png';
+    options.authenticator.loginBlurb = ['<p>This is a login page.</p>'];
+    options.authenticator.indieAuthBlurb = ['<p>Describe what IndieAuth allows one to do.</p>'];
+    options.authenticator.userBlurb = ['<p>Describe user login.</p>'];
+    const result = LoginHTML(ctx, options);
+    lintHtml(result);
+    assert(result);
+  });
+
+  it('covers no indieAuth', function () {
+    options.authenticator.authnEnabled = [];
+    const result = LoginHTML(ctx, options);
+    lintHtml(result);
+    assert(result);
+  });
+
+  it('covers insecure not allowed', function () {
+    ctx.clientProtocol = undefined;
+    const result = LoginHTML(ctx, options);
+    lintHtml(result);
+    assert(result);
+  });
+
+  it('covers insecure allowed', function () {
+    ctx.clientProtocol = 'http';
+    options.authenticator.secureAuthOnly = false;
+    const result = LoginHTML(ctx, options);
+    lintHtml(result);
+    assert(result);
+  });
+
+});
\ No newline at end of file