fix changelog
[squeep-indie-auther] / test / src / template / admin-html.js
1 'use strict';
2
3 const assert = require('assert');
4 const template = require('../../../src/template/admin-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('Admin HTML Template', function () {
22 let ctx, config;
23 beforeEach(function () {
24 ctx = {
25 profilesScopes: {
26 scopeIndex: {
27 'scope': {
28 application: '',
29 description: '',
30 isPermanent: true,
31 isManuallyAdded: false,
32 profiles: ['https://example.com/'],
33 },
34 'other_scope': {
35 application: 'app1',
36 description: '',
37 isPermanent: false,
38 isManuallyAdded: true,
39 profiles: [],
40 },
41 'more_scope': {
42 application: 'app2',
43 description: '',
44 isPermanent: false,
45 isManuallyAdded: false,
46 profiles: [],
47 },
48 'scopitty_scope': {
49 application: 'app2',
50 description: '',
51 isPermanent: false,
52 isManuallyAdded: false,
53 profiles: [],
54 },
55 'last_scope': {
56 application: 'app1',
57 description: '',
58 isPermanent: false,
59 isManuallyAdded: false,
60 profiles: [],
61 },
62 },
63 profiles: ['https://example.com/'],
64 },
65 tokens: [
66 {
67 codeId: 'xxx',
68 clientId: 'https://client.example.com/',
69 profile: 'https://profile.example.com/',
70 created: new Date(),
71 expires: null,
72 isRevoked: false,
73 },
74 {
75 codeId: 'yyy',
76 clientId: 'https://client.example.com/',
77 profile: 'https://profile.example.com/',
78 isToken: true,
79 created: new Date(Date.now() - 86400000),
80 refreshed: new Date(),
81 expires: new Date(Date.now() + 86400000),
82 isRevoked: true,
83 },
84 {
85 codeId: 'zzz',
86 clientId: 'https://client.exmaple.com/',
87 profile: 'https://profile.example.com/',
88 resource: 'https://resource.example.com/',
89 created: new Date(),
90 scopes: ['read'],
91 },
92 ],
93 };
94 config = new Config('test');
95 });
96 it('renders', async function () {
97 const result = template(ctx, config);
98 await lintHtml(result);
99 assert(result);
100 });
101 it('renders no tokens', async function () {
102 ctx.tokens = [];
103 const result = template(ctx, config);
104 await lintHtml(result);
105 assert(result);
106 });
107 it('covers options', async function () {
108 delete ctx.profilesScopes.profiles;
109 delete ctx.profilesScopes.scopeIndex.scope.profiles;
110 delete ctx.tokens;
111 const result = template(ctx, config);
112 await lintHtml(result);
113 assert(result);
114 });
115 }); // Admin HTML Template