b599df346cf9d7d6d61cd032172cf6d1c73f3dff
[squeep-indie-auther] / test / src / template / authorization-request-html.js
1 /* eslint-env mocha */
2 'use strict';
3
4 const assert = require('assert');
5 const template = require('../../../src/template/authorization-request-html');
6 const Config = require('../../../config');
7 const StubLogger = require('../../stub-logger');
8 const lint = require('html-minifier-lint').lint; // eslint-disable-line node/no-unpublished-require
9
10 const stubLogger = new StubLogger();
11
12 function lintHtml(html) {
13 const result = lint(html);
14 stubLogger.debug('validHtml', '', { result, html });
15 assert(!result);
16 }
17
18 describe('Authorization Request HTML Template', function () {
19 let ctx, config;
20 beforeEach(function () {
21 ctx = {};
22 config = new Config('test');
23 });
24 it('renders', function () {
25 const result = template(ctx, config);
26 lintHtml(result);
27 assert(result);
28 });
29 it('covers options', function () {
30 ctx.session = {
31 scope: ['profile', 'email'],
32 scopeIndex: {
33 'profile': {
34 description: 'Profile',
35 },
36 'email': {
37 description: 'Email',
38 },
39 'create': {
40 description: 'Create',
41 profiles: ['https://exmaple.com/profile'],
42 },
43 },
44 me: new URL('https://example.com/profile'),
45 profiles: ['https://another.example.com/profile', 'https://example.com/profile'],
46 clientIdentifier: {
47 items: [{
48 properties: {
49 url: 'https://client.example.com/app/',
50 summary: 'This is an app',
51 logo: 'https://client.example.com/app/logo.png',
52 name: 'Some Fancy Application',
53 },
54 }],
55 },
56 clientId: 'https://client.example.com/app/',
57 persist: 'encodedData',
58 redirectUri: 'https://client.example.com/app/_return',
59 };
60 const result = template(ctx, config);
61 lintHtml(result);
62 assert(result);
63 });
64 it('covers alternate scopes and client logo', function () {
65 ctx.session = {
66 scope: ['profile', 'email'],
67 scopeIndex: {
68 'profile': {
69 description: 'Profile',
70 },
71 'email': {
72 description: 'Email',
73 },
74 'create': {
75 description: 'Create',
76 profiles: ['https://example.com/profile'],
77 },
78 'other': {
79 description: 'Another Scope',
80 profiles: ['https://example.com/profile'],
81 },
82 },
83 me: new URL('https://example.com/profile'),
84 profiles: ['https://another.example.com/profile', 'https://example.com/profile'],
85 clientIdentifier: {
86 items: [{
87 properties: {
88 url: 'https://client.example.com/app/',
89 summary: 'This is an app',
90 logo: [{
91 value: 'https://client.example.com/app/logo.png',
92 alt: 'alt',
93 }],
94 name: 'Some Fancy Application',
95 },
96 }],
97 },
98 clientId: 'https://client.example.com/app/',
99 persist: 'encodedData',
100 redirectUri: 'https://client.example.com/app/_return',
101 };
102 const result = template(ctx, config);
103 lintHtml(result);
104 assert(result);
105 });
106 it('covers partial data', function () {
107 ctx.session = {
108 scope: ['profile', 'email', 'create'],
109 profiles: ['https://another.example.com/profile', 'https://example.com/profile'],
110 clientIdentifier: {
111 items: [{
112 properties: {
113 url: 'https://client.example.com/app/',
114 summary: 'This is an app',
115 logo: 'https://client.example.com/app/logo.png',
116 name: 'Some Fancy Application',
117 },
118 }],
119 },
120 clientId: 'https://client.example.com/app/',
121 persist: 'encodedData',
122 redirectUri: 'https://client.example.com/app/_return',
123 };
124 const result = template(ctx, config);
125 lintHtml(result);
126 assert(result);
127 });
128 it('covers partial data', function () {
129 ctx.session = {
130 scope: ['profile', 'email', 'create'],
131 profiles: [],
132 clientIdentifier: {
133 items: [{
134 }],
135 },
136 clientId: 'https://client.example.com/app/',
137 persist: 'encodedData',
138 redirectUri: 'https://client.example.com/app/_return',
139 };
140 const result = template(ctx, config);
141 lintHtml(result);
142 assert(result);
143 });
144 }); // Authorization Request HTML Template