@suffolklitlab/alkiln 4.0.0-pre-api.8 → 4.0.0-pre-api.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,177 +0,0 @@
1
- const fs = require('fs');
2
-
3
- require('dotenv').config();
4
-
5
- const session_vars = require( './session_vars' );
6
-
7
- /**
8
- * This code assumes that this module is run as part of a GitHub Action. If the
9
- * customer is running it as a CLI tool, then they are on their own.
10
- */
11
-
12
- /* This file provides both `process.env` variables and other variables
13
- * that are needed in a similar way, but are not `process.env` variables themselves,
14
- * though they are based on the `process.env` variables.
15
- *
16
- * The alternative seems to be some `process.env` type variables and some `foo`
17
- * variables without great ways to differentiate between them. That or duplicate
18
- * fiddly work in multiple files.
19
- *
20
- * The need to get and set project name, etc. makes me wonder if we should create
21
- * a class with getters and setters, but general wisdom is that it's a bad idea and
22
- * maybe it comes to mind because I'm used to asking for `env_vars.CAPS_CASE`. Another
23
- * alternative is `env_vars.get( 'CAPS_CASE' )` and `env_vars.set( 'CAPS_CASE', 'value' )`
24
- */
25
-
26
- // DEBUG is not required.
27
-
28
- const env_vars = {
29
- PLAYGROUND_ID: process.env.PLAYGROUND_ID,
30
- PLAYGROUND_EMAIL: process.env.PLAYGROUND_EMAIL,
31
- PLAYGROUND_PASSWORD: process.env.PLAYGROUND_PASSWORD,
32
- BASE_URL: process.env.BASE_URL,
33
- REPO_URL: process.env.REPO_URL,
34
- DEBUG: process.env.DEBUG,
35
- };
36
-
37
- /**
38
- * For each field in env_vars, check if the value is defined in an environment
39
- * variable, and throw an exception if it is not.
40
- *
41
- * @throws ReferenceError with a message for all missing variables.
42
- */
43
- env_vars.validateEnvironment = function() {
44
-
45
- // We are checking for BASE_URL, but we are referring it as SERVER_URL as that
46
- // is the name used in GitHub secrets, which is what most devs will be using.
47
-
48
- let errorMessage = '';
49
-
50
- // Since this code will most often be run in GitHub, I'm going to build a single error message that outlines all missing variables. Otherwise, a developer
51
- // will have to run their pipeline an incredible number of times to discover all the missing variables.
52
- if (!process.env.PLAYGROUND_ID)
53
- {
54
- errorMessage += '\nThe PLAYGROUND_ID GitHub secret must be defined. The PLAYGROUND_ID is the ID of the Docassemble suite to run.'
55
- }
56
- if (!process.env.PLAYGROUND_EMAIL)
57
- {
58
- errorMessage += '\nThe PLAYGROUND_EMAIL GitHub secret must be defined. The PLAYGROUND_EMAIL is the e-mail address of the test user to run the Docassemble suite.'
59
- }
60
- if (!process.env.PLAYGROUND_PASSWORD)
61
- {
62
- errorMessage += '\nThe PLAYGROUND_PASSWORD GitHub secret must be defined. The PLAYGROUND_PASSWORD is your test user\'s password for the test suite.'
63
- }
64
- if (!process.env.BASE_URL)
65
- {
66
- errorMessage += `\nThe SERVER_URL GitHub secret must be defined. The SERVER_URL is the URL of the Docassemble Server where the tests should be run.`;
67
- }
68
- if (!process.env.REPO_URL)
69
- {
70
- errorMessage += `\nThe REPO_URL GitHub secret must be defined. The REPO_URL is the URL to the Git repo whose Actions are being run.`;
71
- }
72
-
73
- errorMessage = errorMessage.trim();
74
-
75
- if (errorMessage !== '')
76
- throw new ReferenceError(errorMessage);
77
- };
78
-
79
- env_vars.validateEnvironment();
80
-
81
- // // Path could be 'refs/branch_name' or 'refs/head/branch_name' and maybe other things
82
- // // Assume branch name is last part of branch path
83
- // if ( process.env.BRANCH_PATH ) {
84
- // let split = process.env.BRANCH_PATH.split('/');
85
- // env_vars.BRANCH_NAME = split[ split.length - 1 ];
86
- // } else {
87
- // env_vars.BRANCH_NAME = 'test'
88
- // }
89
-
90
- // // ---- Project name ----
91
- // let no_starting_digit = ( 'testing' + env_vars.BRANCH_NAME ).replace( /^[0-9]+/i, '' );
92
- // env_vars.PROJECT_BASE_NAME = no_starting_digit.replace( /[^A-Za-z0-9]+/gi, '' );
93
-
94
- // const project_name_file_path = '_al_test_project_name.json';
95
- // env_vars.setProjectName = function ( value ) {
96
- // // As long as it's a string, it can be made safe for a project name
97
- // if ( typeof value !== 'string' ) { throw new TypeError(`The project's name must start as a string. It was ${ value }.`); }
98
- // // Make the name safe for a project name
99
- // let no_starting_digit = value.replace( /^[0-9]+/i, '' );
100
- // let alphanumeric = no_starting_digit.replace( /[^A-Za-z0-9]+/gi, '' );
101
- // // Create or modify a file to store the actual name of the project
102
- // // for later deletion as internal values and context get destroyed before
103
- // // the takedown command that comes later. It's a string, not a list, to avoid
104
- // // the list getting out of date and deleting another test's project.
105
- // fs.writeFileSync( project_name_file_path, JSON.stringify( alphanumeric ));
106
- // console.log( `Saved new project name: ${ alphanumeric }` );
107
-
108
- // return alphanumeric;
109
- // }
110
-
111
- // env_vars.getProjectName = function () {
112
- // /* Get the stored name of the project that was created on the
113
- // * server - the base project name might have been adjusted to
114
- // * avoid overwriting existing project. */
115
- // if ( env_vars.DEBUG ) { console.trace( `Getting project name` ); }
116
- // let actual_proj_name = null;
117
- // // Avoid race coditions possibly caused by checking for existence first
118
- // try {
119
- // actual_proj_name = JSON.parse( fs.readFileSync( project_name_file_path ));
120
- // if ( env_vars.DEBUG ) { console.log( `Project name from file is ${ actual_proj_name }.` ); }
121
- // } catch ( error ) {} // Do nothing
122
-
123
- // // If no such file existed or value was invalid, set up the file with a basic name
124
- // if ( !actual_proj_name ) {
125
- // actual_proj_name = env_vars.setProjectName( env_vars.PROJECT_BASE_NAME );
126
- // }
127
-
128
- // if ( env_vars.DEBUG ) { console.log( `Processed project name is "${ actual_proj_name }"` ); }
129
- // return actual_proj_name;
130
- // };
131
-
132
- // env_vars.cleanUpProjectName = function () {
133
- // /* Delete stored name of project */
134
- // // Avoid race coditions possibly caused by checking for existence first
135
- // // Delete file if possible
136
- // try { fs.unlinkSync( project_name_file_path ); }
137
- // catch ( error ) {
138
- // console.warn(`After trying to delete the project created for the test, the file containing the name of project did not exist. ${ error }`)
139
- // }
140
- // };
141
-
142
- // Notes: We were using `new_session=1` in the url args, but it wasn't
143
- // always working. The idea was to save each session so we could look
144
- // back on it if needed. Aside from the fact that you usually need to log in
145
- // to make the sessions retrievable (though if you're using `interview_list()`
146
- // you can get them anyway), it also has inconsistent behavior when
147
- // `sessions are unique`` or `temporary session` or use `interview_list()`
148
- // and/or respond immediately with a `command()`. Three ways to avoid this:
149
- // 1. x Start a new browser instead of just a new page each time. Lengthens the tests.
150
- // 1. √ Visit `/user/sign-out` (needed even if the user is not logged in)
151
- // 1. x (seems to be causing a 'Unable to locate interview session' error
152
- // instead) Use `reset=2` instead , which will not save the previous session at all. It
153
- // Will not just restart any existing interview sessions, it will also
154
- // clear out the browser session's memory of what other interviews the user has
155
- // visited in the same browser session.
156
- env_vars.getBaseInterviewURL = function () {
157
- /* Return the part of the interview URL that comes before the filename.
158
- * Depends on the project name, which may have been changed. */
159
- let new_session = `/interview?new_session=1&i=docassemble.playground`;
160
- return `${ session_vars.get_da_server_url() }${ new_session }${ env_vars.PLAYGROUND_ID }${ session_vars.get_project_name() }%3A`;
161
- };
162
- env_vars.BASE_INTERVIEW_URL = env_vars.getBaseInterviewURL();
163
-
164
-
165
- // // These are actually the words that are on the buttons or links
166
- // // that change the language of the interview. Have not yet detected
167
- // // another distinguishing feature
168
- // if ( process.env.EXTRA_LANGUAGES && process.env.EXTRA_LANGUAGES !== 'default' ) {
169
- // env_vars.EXTRA_LANGUAGES = process.env.EXTRA_LANGUAGES.split(', ');
170
- // } else {
171
- // env_vars.EXTRA_LANGUAGES = [];
172
- // }
173
-
174
- env_vars.EXTRA_LANGUAGES = session_vars.get_languages();
175
-
176
-
177
- module.exports = env_vars;
@@ -1,53 +0,0 @@
1
- const chai = require('chai');
2
- const expect = chai.expect;
3
-
4
- const env_vars = require("../../lib/utils/env_vars.js");
5
- const validateEnvironment = env_vars.validateEnvironment;
6
-
7
- describe('env_vars', function () {
8
- describe('validateEnvironment', function() {
9
-
10
- /**
11
- * All required variables should be defined in .env. For reference, those variables are the following:
12
- *
13
- * PLAYGROUND_ID
14
- * PLAYGROUND_EMAIL
15
- * PLAYGROUND_PASSWORD
16
- * BASE_URL
17
- * REPO_URL
18
- */
19
- it("All variables set", function() {
20
- env_vars.validateEnvironment();
21
- });
22
-
23
- /**
24
- * This test has an ordering dependency with the test below. I'm not certain if I am getting lucky or if I need to explicitly declare the order.
25
- */
26
- it("One variable missing", function() {
27
- delete process.env.PLAYGROUND_PASSWORD;
28
-
29
- expect(env_vars.validateEnvironment).to.throw(ReferenceError, /PLAYGROUND_PASSWORD/);
30
- });
31
-
32
- /**
33
- * Delete all environment variables before validating the variables.
34
- */
35
- it("No variables set", function() {
36
- delete process.env.PLAYGROUND_ID;
37
- delete process.env.PLAYGROUND_EMAIL;
38
- delete process.env.PLAYGROUND_PASSWORD;
39
- delete process.env.BASE_URL;
40
- delete process.env.REPO_URL;
41
-
42
- // This test just tests that the variable names show up in a fixed order.
43
- //
44
- // For whatever reason, /PLAYGROUND_ID.*PLAYGROUND_EMAIL.*PLAYGROUND_PASSWORD.*SERVER_URL.*REPO_URL/ simply wouldn't work once I got to the first letter
45
- // after the second underscore so I have used separate matchers.
46
- expect(env_vars.validateEnvironment).to.throw(ReferenceError, /PLAYGROUND_ID/);
47
- expect(env_vars.validateEnvironment).to.throw(ReferenceError, /PLAYGROUND_EMAIL/);
48
- expect(env_vars.validateEnvironment).to.throw(ReferenceError, /PLAYGROUND_PASSWORD/);
49
- expect(env_vars.validateEnvironment).to.throw(/SERVER_URL/);
50
- expect(env_vars.validateEnvironment).to.throw(/REPO_URL/);
51
- });
52
- });
53
- });