Minor changes, added example classes test

This commit is contained in:
mrfry 2021-05-04 10:28:20 +02:00
parent 8801bb96cd
commit d8b0c28471
4 changed files with 35 additions and 10 deletions

View file

@ -19,8 +19,7 @@
"nextdir": "nextStatic/qminingPagePublic", "nextdir": "nextStatic/qminingPagePublic",
"name": "qmining", "name": "qmining",
"urls": [ "urls": [
"qmining.frylabs.net", "qmining.frylabs.net"
"localhost"
], ],
"isNextJs": true "isNextJs": true
}, },
@ -31,7 +30,8 @@
], ],
"name": "api", "name": "api",
"urls": [ "urls": [
"api.frylabs.net" "api.frylabs.net",
"localhost"
] ]
}, },
"main": { "main": {

View file

@ -12,7 +12,6 @@ function setup(data: SubmoduleData): void {
const publicDir = publicdirs[0] const publicDir = publicdirs[0]
const userFilesDir = publicDir + 'userFiles' const userFilesDir = publicDir + 'userFiles'
if (!utils.FileExists(userFilesDir)) { if (!utils.FileExists(userFilesDir)) {
utils.CreatePath(userFilesDir, true) utils.CreatePath(userFilesDir, true)
} }
@ -20,6 +19,10 @@ function setup(data: SubmoduleData): void {
app.get('/listUserDir', (req: Request, res) => { app.get('/listUserDir', (req: Request, res) => {
logger.LogReq(req) logger.LogReq(req)
if (!utils.FileExists(userFilesDir)) {
utils.CreatePath(userFilesDir, true)
}
const subdir: any = req.query.subdir const subdir: any = req.query.subdir
if (subdir) { if (subdir) {
@ -168,7 +171,7 @@ function setup(data: SubmoduleData): void {
} }
utils utils
.uploadFile(req, userFilesDir + '/' + safeDir) .uploadFile(req, userFilesDir + '/' + safeDir, true)
.then((body) => { .then((body) => {
logger.Log( logger.Log(
`Successfull upload ${body.filePath}`, `Successfull upload ${body.filePath}`,

25
src/utils/classes.test.ts Normal file
View file

@ -0,0 +1,25 @@
import { compareString } from './classes'
const testCases: Array<{ s1: string; s2: string; res: number }> = [
{ s1: 'hello', s2: 'hello', res: 100 },
{ s1: 'aaaaa', s2: 'bbbbb', res: 0 },
{
s1: 'Mely állítás nem igaz a tőzsdékre?',
s2: 'Mely állítás nem igaz a tőzsdékre?',
res: 100,
},
{
s1: 'Mely állítás nem igaz a tőzsdékre?',
s2: 'Ez egy teljesen más mondat',
res: 0,
},
{ s1: 'cHar caSe tESt', s2: 'ChaR cAse TEst', res: 0 },
]
testCases.forEach((currCase) => {
const { s1, s2, res } = currCase
test(`String compare tests: "${s1}" & "${s2}" should be: ${res}%`, () => {
expect(compareString(s1, s1.split(' '), s2, s2.split(' '))).toBe(res)
})
})

View file

@ -65,10 +65,7 @@ function getSubjNameWithoutYear(subjName: string): string {
// --------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------
function simplifyString(toremove) { function simplifyString(toremove) {
return toremove return toremove.replace(/\s/g, ' ').replace(/\s+/g, ' ').toLowerCase()
.replace(/\s/g, ' ')
.replace(/\s+/g, ' ')
.toLowerCase()
} }
function removeStuff( function removeStuff(
@ -92,7 +89,7 @@ function removeUnnecesarySpaces(toremove: string) {
return normalizeSpaces(toremove).replace(/\s+/g, ' ') return normalizeSpaces(toremove).replace(/\s+/g, ' ')
} }
function compareString( export function compareString(
s1: string, s1: string,
s1a: Array<string>, s1a: Array<string>,
s2: string, s2: string,