Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign up test function and automated testing with git action workflows #932

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run Tests

on:
pull_request:
branches:
- master
- develop

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'

- name: Install dependencies and ESLint
run: |
npm install
npm install eslint eslint-config-google

- name: Run Jest tests and linting
run: |
npm run lint && npm test
168 changes: 85 additions & 83 deletions apps/signup/signup.js
Original file line number Diff line number Diff line change
@@ -1,119 +1,121 @@
var userSignupUrl = "../../data/User/post";
var protoTokenUrl = "../../auth/Token/proto";
var userSignupUrl = '../../data/User/post';
var protoTokenUrl = '../../auth/Token/proto';
var permissions;
const store = new Store('../../data/');

function addUser(){
var email = document.getElementById("mail").value
var filters = document.getElementById("filters").value
function addUser() {
var email = document.getElementById('mail').value;
var filters = document.getElementById('filters').value;
// var attr = document.querySelector('input[name="attr"]:checked').value
var attrEle = document.getElementById("attr");
var attrEle = document.getElementById('attr');
var attr = attrEle.options[attrEle.selectedIndex].value;

if (!(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(email))) {
window.alert("Please enter a valid email");
window.alert('Please enter a valid email');
return;
}

var userType = "Null"
if (attr == "3"){
userType = "Admin"
var userType = 'Null';
if (attr == '3') {
userType = 'Admin';
}
if (attr == "2"){
userType = "Editor"
if (attr == '2') {
userType = 'Editor';
}

store.getUserPermissions(getUserType())
.then(response => response.text())
.then((data) => {
return (data ? JSON.parse(data) : null);
})
.then((data)=> {
if(data===null)
return;
.then((response) => response.text())
.then((data) => {
return (data ? JSON.parse(data) : null);
})
.then((data)=> {
if (data===null) {
return;
}
permissions = data;
return;
})
.then((resp) => {
return fetch(protoTokenUrl)
})
.then((response) => {
// console.log(response);
return response.json();
})
.then((data) => {
return data.exists
})
.then((x) => {
if (x) {
var doc = {email: email, userType: userType, userFilter:filters}
fetch(userSignupUrl, {
method: 'POST',
mode: 'cors', // no-cors, cors, *same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(doc),
}).then(x=>{
if (x.status>=400){
throw "failed to sign up user"
}
x.json()
}).then(x=>{
window.alert("User registered successfully")
}).catch(e=>{
// window.alert("error!")
console.error(e)
});
} else {
if (permissions.user && permissions.user.post == true) {
var doc = {email: email, userType: userType, userFilter:filters}
fetch(userSignupUrl, {
})
.then((resp) => {
return fetch(protoTokenUrl);
})
.then((response) => {
// console.log(response);
return response.json();
})
.then((data) => {
return data.exists;
})
.then((x) => {
if (x) {
var doc = {email: email, userType: userType, userFilter: filters};
fetch(userSignupUrl, {
method: 'POST',
mode: 'cors', // no-cors, cors, *same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(doc),
}).then(x=>{
if (x.status>=400){
throw "failed to sign up user"
}).then((x)=>{
if (x.status>=400) {
throw new Error('failed to sign up user');
}
x.json()
}).then(x=>{
window.alert("User registered successfully");
}).catch(e=>{
x.json();
}).then((x)=>{
window.alert('User registered successfully');
}).catch((e)=>{
// window.alert("error!")
console.error(e);
});
} else {
if (permissions.user && permissions.user.post == true) {
var doc = {email: email, userType: userType, userFilter: filters};
fetch(userSignupUrl, {
method: 'POST',
mode: 'cors', // no-cors, cors, *same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(doc),
}).then((x)=>{
if (x.status>=400) {
throw new Error('failed to sign up user');
}
x.json();
}).then((x)=>{
window.alert('User registered successfully');
}).catch((e)=>{
// window.alert("error!")
console.error(e)
});
} else {
store.requestToCreateUser(email, filters, userType);
}
}
});
console.error(e);
});
} else {
store.requestToCreateUser(email, filters, userType);
}
}
});
}

$(window).on('load', function() {
$('#sub').text('Sign up');
$('#sub').removeAttr('disabled');

store.getUserPermissions(getUserType())
.then(response => response.text())
.then((data) => {
return (data ? JSON.parse(data) : null);
})
.then((data)=> {
if(data===null)
return;
.then((response) => response.text())
.then((data) => {
return (data ? JSON.parse(data) : null);
})
.then((data)=> {
if (data===null) {
return;
}
permissions = data;
});
});
});

function loginPage(){
const url = "/login.html";
function loginPage() {
const url = '/login.html';
window.location.href = url;
}
}
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testEnvironment: 'jsdom',
};