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

test #27

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open

test #27

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e8e9a7b
test
lilyh14 Jun 14, 2021
79a06ae
fixed file name and updated some of the scripts
lilyh14 Jun 14, 2021
b6c3336
Redid auto scripts for mock tests
lilyh14 Jun 14, 2021
f21570a
Reformat
lilyh14 Jul 12, 2021
9108fba
added scripts to try to get the db dump working
lilyh14 Jul 12, 2021
caf3f3d
Fixed action name
lilyh14 Jul 12, 2021
6e84f78
changed test workflow
lilyh14 Jul 12, 2021
3ef6a71
fixed the workflow for the docker-compose command
lilyh14 Jul 12, 2021
48fca0a
fixed pathing for the docker compose up
lilyh14 Jul 12, 2021
bde814f
try #2 for fixing pathing
lilyh14 Jul 12, 2021
183b40a
Moved the docker-composed file
lilyh14 Jul 12, 2021
873d3a8
process of fixing error of not finding the docker-compose file
lilyh14 Jul 12, 2021
25eaa30
moved docker-compose to be in same directory as dockerfile
lilyh14 Jul 12, 2021
a7e75e3
Changed command for the docker-compose
lilyh14 Jul 12, 2021
1c9563a
updating path
lilyh14 Jul 12, 2021
caecf90
updated path in workflow
lilyh14 Jul 12, 2021
ea803fc
added script for docker compose
lilyh14 Jul 15, 2021
800a139
deleted stop docker command
lilyh14 Jul 15, 2021
ca97d2d
moved docker compose command to entrypoint
lilyh14 Jul 15, 2021
6d4b907
Moving tests
lilyh14 Jul 15, 2021
e109cb8
moved tests out of test file with buildtestdeploy
lilyh14 Jul 15, 2021
870613f
workflow not picking up tests - changed one of the names
lilyh14 Jul 15, 2021
5171011
deleted other tests
lilyh14 Jul 15, 2021
e0a0e89
Revert "Redid auto scripts for mock tests"
lilyh14 Jul 15, 2021
c3c9aa0
added back the mocks action folder
lilyh14 Jul 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build-test-deploy/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
]
]
}
8 changes: 4 additions & 4 deletions build-test-deploy/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ docker pull "$gpr_compile" || true
docker build -t "$gpr_compile:$image_tag" -t "$gpr_compile:latest" -t "$heroku_compile" --cache-from "$gpr_compile" -f ./compile/Dockerfile ./compile

# Test
# docker-compose up -d
# ready=false
# do
# ready=docker-compose logs | grep "strapi ready"
docker-compose up -d
ready=false
do
ready=docker-compose logs | grep "strapi ready"
# while ("$ready" = false)
# cd test
# yarn functional
Expand Down
3 changes: 3 additions & 0 deletions build-test-deploy/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
testTimeout: 20000
}
16 changes: 16 additions & 0 deletions build-test-deploy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"dependencies": {
"@babel/preset-env": "^7.10.4",
"axios": "^0.19.2",
"babel-jest": "^26.1.0",
"jest": "^26.6.3",
"k6": "^0.0.0"
},
"scripts": {
"start": "docker-compose -f ../docker-compose.test.yml up",
"functional": "jest ./functional/*.test.js",
"integration": "jest ./integration/*.test.js",
"performance": "k6 run ./performance/*.test.js"
},
"type": "module"
}
108 changes: 108 additions & 0 deletions build-test-deploy/request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
'use strict'

import axios from 'axios'
//import { get } from 'k6/http'
//axios.defaults.adapter = require('axios/lib/adapters/http');
const host = 'http://localhost:1337/api'

export const getToken = () => {
return sessionStorage.getItem('token') || null;
}

const GET = 'GET';
const PUT = 'PUT';
const POST = 'POST';
const DELETE = 'DELETE'

const makeRequest = async ( {method, path, data, auth = false, error}) => {
let res = null;
let err = null;
const config = auth ? {
headers: {
Authorization:
`Bearer ${token}`
}
} : null;

try {
switch (method) {
case GET:
res = (await axios.get(path, config)).data;
break;
case POST:
res = (await axios.post(path, data, config)).data;
break;
case PUT:
res = (await axios.put(path, data, config)).data;
break;
case DELETE:
res = (await axios.delete(path, config)).data;
break;
default:
throw Error('Invalid method.')
}
} catch (e) {
console.error(e);
err = error ? error : "An error occurred."
}

return {data: res, err: err}
};

export const getPublicRequestModule = () => axios.create({
baseURL: host
})

export const getAuthorizedRequestModule = (token) => axios.create({
baseURL: host,
headers: {
Authorization: `Bearer ${token}`
}
})

export const getStudentLoginData = async () => (
makeRequest({
method: 'GET',
path: `${host}/classrooms/join/0450`,
auth: true,
error: "Student login data information could not be retrieved",
})
)

export const getMentorLoginData = async (token) => (
makeRequest({
method: 'GET',
path: `${host}/classrooms/1`,
auth: true,
error: "Mentor login data information could not be retrieved",
token: token
})
)

export const getStudents = async (code) => (
makeRequest({
method: 'GET',
path: `${host}/classrooms/join/${code}`,
error: "Student info could not be retrieved.",
})
)

export const postJoin = async (code, ids) => (
makeRequest({
method: POST,
path: `${host}/classrooms/join/${code}`,
data: {
"students": ids,
},
error: "Login failed.",
})
);

export const getStudentClassroom = async () => (
makeRequest({
method: 'GET',
path: `${host}/classrooms/student`,
auth: true,
error: "Classroom information could not be retrieved",
})
);
87 changes: 87 additions & 0 deletions build-test-deploy/studentMocks.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* @jest-environment node
*/
'use strict'

import { getPublicRequestModule, getAuthorizedRequestModule, getStudentLoginData, getStudents, getStudentClassroom, postJoin } from './request'

const publicRequest = getPublicRequestModule()
var adminRequest
var studentRequest

//Tests

//localhost:1337/api/classrooms/join/0450
beforeAll(async () => {
const { data: admin } = await publicRequest.post('/admin/auth/local', {
identifier: 'test',
password: '123456'
})
adminRequest = getAuthorizedRequestModule(admin.jwt)
//console.log("admin token: ", admin.jwt)
})


test('student login drop down data is populated correctly' , async () => {
const response = await adminRequest.get(`/classrooms/join/0450`);
expect(response).toMatchObject({
"data": [
{
"character": "🦍",
"id": 1,
"name": "Nick I.",
},
{
"character": "🐼",
"id": 2,
"name": "Adam T.",
},
{
"character": "🤡",
"id": 3,
"name": "Dakota R.",
},
],
})
})

test('A user can login with classroom code', async () => {
const response = await adminRequest.get(`/classrooms/join/0450`);
expect(response.status).toBe(200)
})

test('A student can login', async () =>{
const res = await postJoin('0450',[1,2,3]);

expect(res.data).toHaveProperty('jwt');
//console.log("student token", res.data.jwt);
studentRequest = getAuthorizedRequestModule(res.data.jwt);
})

test('student can view day selections', async () => {
const response = await studentRequest.get('/classrooms/student');
expect(response).toMatchObject({
"data": {
"learning_standard": {
"days":[
{
"id": 1,
"learning_standard": 1,
"number": "1",
"template": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"controls_if\" id=\"QJ(1[6#4Ys@+p~@Ryl|Z\" x=\"117\" y=\"178\"><value name=\"IF0\"><block type=\"logic_compare\" id=\"x5M=__I|GXzRT:u6nz]_\"><field name=\"OP\">EQ</field><value name=\"A\"><block type=\"math_number\" id=\"?L[7sHbFFX{X-d({Qgi!\"><field name=\"NUM\">0</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"qfOmU9isz_01I8~u#sSW\"><field name=\"NUM\">0</field></block></value></block></value><statement name=\"DO0\"><block type=\"math_change\" id=\";y@:{=LW6[@|j,1*.6C]\"><field name=\"VAR\">item</field><value name=\"DELTA\"><block type=\"math_number\" id=\"m0.eI+XUsK/KXsTo3}#B\"><field name=\"NUM\">0</field></block></value></block></statement></block></xml>",
},
{
"id": 2,
"learning_standard": 1,
"number": "2",
"template": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"controls_if\" id=\"+tDwx%uD*;|/%MoHiBuD\" x=\"72\" y=\"141\"><value name=\"IF0\"><block type=\"variables_get\" id=\"iQ,uNAfjOn;[Fhd|~lzS\"><field name=\"VAR\">item</field></block></value></block></xml>",
},
{
"id": 3,
"learning_standard": 1,
"number": "3",
"template": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"io_digitalwrite\" id=\"j#m#H23NIQH5Wz^I2c^G\" x=\"70\" y=\"224\"><field name=\"PIN\">0</field><value name=\"STATE\"><block type=\"io_highlow\" id=\"7.^n|ek_3R;_Q`K9M!;/\"><field name=\"STATE\">HIGH</field></block></value></block></xml>",
}]}
}
})
})
82 changes: 82 additions & 0 deletions build-test-deploy/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @jest-environment node
*/
'use strict'

import { getPublicRequestModule, getAuthorizedRequestModule } from './request'

const publicRequest = getPublicRequestModule()
var schoolId
var userId
var classroomId
var learningStandardId, learningStandardName = 'Something'
var studentId
var unitId, gradeId
var adminRequest
var mentorRequest
var contentcreatorRequest

//
// Setup before running tests
//
beforeAll(async () => {

// login as an admin
const { data: admin } = await publicRequest.post('/admin/auth/local', {
identifier: 'test',
password: '123456'
})

// create an admin request instance
const adminRequest = getAuthorizedRequestModule(admin.jwt)

console.log("token: ", admin.jwt)

//
// populate the database
//
const { data: school } = await adminRequest.post('/schools', {
name: 'UF1'
})
console.log("School ID: ", school.id)
schoolId = school.id

const { data: grade } = await adminRequest.post('/grades',{
name: '11th'
})
gradeId = grade.id

const { data: classroom } = await adminRequest.post('/classrooms', {
name: 'test',
school: school.id,
grade: grade.id
})
classroomId = classroom.id
console.log("This is classroom id", classroomId)

const { data: learningStandard } = await adminRequest.post('/learning-standards', {
number: 1.1,
name: learningStandardName
})

learningStandardId = learningStandard.id

const { data: units } = await adminRequest.post('units', {
number: 1,
name: 'Unit',
grade: gradeId
})

unitId = units.id
})

//Student Tests


test('student can login', async () => {
const response = await publicRequest.post('/', {
identifier: '0450',
})

expect(response.status).toBe(200)
})
Loading