Browse Source

First successful fully automated test is working and now I can breathe better.

cleanuptesting
Zed A. Shaw 3 months ago
parent
commit
4f374d7a81
6 changed files with 27 additions and 47 deletions
  1. +0
    -38
      ecosystem.config.js
  2. +6
    -3
      lib/data.js
  3. +2
    -4
      src/components/Nav.svelte
  4. +1
    -0
      src/node_modules/data.js
  5. +1
    -1
      src/routes/index.svelte
  6. +17
    -1
      tests/ui/login.spec.js

+ 0
- 38
ecosystem.config.js View File

@@ -1,38 +0,0 @@
module.exports = {
apps :
[
{
"kill_retry_time": 100,
"windowsHide": true,
"treekill": true,
"automation": true,
"pmx": true,
"instance_var": "NODE_APP_INSTANCE",
"watch": true,
"autorestart": true,
"vizion": true,
"merge_logs": true,
"namespace": "default",
"name": "auth",
"node_args": [],
"exec_interpreter": "node",
"exec_mode": "fork_mode",
"vizion_running": false,
"restart_time": 0,
"unstable_restarts": 0,
"version": "0.0.1",
"node_version": "12.16.0"
}
],

deploy : {
production : {
user : 'node',
host : '212.83.163.1',
ref : 'origin/master',
repo : 'git@github.com:repo.git',
path : '/var/www/production',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
}
}
};

+ 6
- 3
lib/data.js View File

@@ -8,11 +8,8 @@ const db = new Database();
console.log("Authenticated:", result);
})();

let last_token;

exports.create_auth_token = async (email) => {
let token = uuid4();

let cursor = await db.query(aql`INSERT {email: ${email}, token: ${token}} INTO auths`);

return token;
@@ -24,3 +21,9 @@ exports.delete_auth_token = async (email) => {
REMOVE auth IN auths`);
}

exports.find_token_with_email = async (email) => {
let cursor = await db.query(aql`FOR auth IN auths
FILTER auth.email == ${email}
RETURN auth.token`);
return await cursor.next();
}

+ 2
- 4
src/components/Nav.svelte View File

@@ -1,6 +1,6 @@
<script>
export let segment;
import { stores } from '@sapper/app';
import { goto, stores } from '@sapper/app';
import { post } from 'utils.js';

const { session } = stores();
@@ -8,9 +8,7 @@ const { session } = stores();
async function logout(event) {
const response = await post('auth/logout');
$session.user = null;
email = '';
token = '';
email_sent = false;
await goto('/');
}
</script>


+ 1
- 0
src/node_modules/data.js View File

@@ -19,3 +19,4 @@ exports.get_auth_token = async (token) => {
return auth;
}

exports.db = db;

+ 1
- 1
src/routes/index.svelte View File

@@ -14,7 +14,7 @@
<h1 class="title is-size-2 has-text-white">
Learn JavaScript<br/>the Hard Way
</h1>
<h1 class="title is-size-4 has-text-grey-lighter">
<h1 data-testid="index-check" class="title is-size-4 has-text-grey-lighter">
Coming Soon
</h1>
<h2 class="subtitle has-text-white-bis has-text-justified">

+ 17
- 1
tests/ui/login.spec.js View File

@@ -6,6 +6,10 @@ const main_user = t.fake_person();

const host = 'http://localhost:3000/';

beforeEach(async () => {
await db.delete_auth_token(main_user.email);
});

afterAll(() => t.close());

it('Can log people in and out', async () => {
@@ -16,7 +20,9 @@ it('Can log people in and out', async () => {

// use the menu to get to the login (assumes tiny window)
await page.click(t.sel('burger'));
await page.waitForSelector(t.sel('login'));
await page.click(t.sel('login'));
await page.click(t.sel('burger')); // TODO: close burger after button click?
// wait for the login page to show up then submit email
await page.waitForSelector(t.sel('email'));
@@ -27,14 +33,24 @@ it('Can log people in and out', async () => {
await t.has_content(page, t.sel('email-sent-msg'), "You've been sent");
// go in through the backend and get the token
let token = 'fake';

// now submit it pretending we got it over an email
await page.waitForSelector(t.sel('token'));
let token = await db.find_token_with_email(main_user.email);
expect(token).toBeDefined();
await page.type(t.sel('token'), token);
await page.click(t.sel('token-button'));
await t.has_content(page, t.sel('login-success'), "You're logged in");

// now log them out to test the full round trip
await page.click(t.sel('burger'));
await page.click(t.sel('logout'));
await page.waitForSelector(t.sel('login'));
await page.click(t.sel('burger'));

await t.has_content(page, t.sel('index-check'), "Coming Soon");

return true;
});


Loading…
Cancel
Save