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