Commit e3b3086f authored by Manish Kumar's avatar Manish Kumar
Browse files

Tests stuff

parent ffac2da7
......@@ -40,6 +40,7 @@ npm-debug.log
yarn-error.log
testem.log
/typings
.scannerwork/*
# System Files
.DS_Store
......
......@@ -58,7 +58,7 @@ exports.updateMove = (req, res) => {
Pokemon.updateMove(req.body.nMove, req.body.id_team, req.body.id_move, (err, data) => {
if (err) {
if (err.kind === "not_found") {
res.send({res: true, body: data});
res.send({res: false, body: data});
} else {
res.status(500).send({
message: "Error updating moves",
......
exports.filterJSON = function (data, type){
var moveNom = "movesPoss";
if(type) moveNom = "movesUtil";
var dataSet = new Set();
var filteredData = [];
var i = -1;
Object.keys(data).forEach(function(key) {
var switcher = false;
var temp = {};
var move = {};
Object.keys(data[key]).forEach(function(key2) {
if(key2 == "id_move") switcher = true;
if(switcher) move[key2] = data[key][key2];
else {temp[key2] = data[key][key2]; };
});
temp[moveNom] = [];
if(dataSet.has(data[key]["id_pokemon"])) filteredData[i][moveNom].push(move);
else {i++;filteredData.push(temp); dataSet.add(data[key]["id_pokemon"]); filteredData[i][moveNom].push(move);}
});
return filteredData;
}
exports.fuseJSON = function (dataUtil, dataPoss){
var fusedJSON = dataUtil;
Object.keys(fusedJSON).forEach(function(key) {
var tempTab = fusedJSON[key]["movesUtil"];
tempTab = tempTab.filter(value =>{
var contain = false;
dataPoss[key]["movesPoss"].forEach(value2 => {if(value.id_move == value2.id_move)contain = true});
return !contain;
});
fusedJSON[key]["movesUtil"] = tempTab;
fusedJSON[key]["movesPoss"] = dataPoss[key]["movesPoss"];
});
return fusedJSON;
}
exports.test = function (){
return true;
}
\ No newline at end of file
......@@ -61,6 +61,7 @@ Pokemon.getTeamUtil = (joueur_id, result) => {
return;
}
console.log(res1);
var dataUtil = filterJSON(res1, true);
sql.query('SELECT t.id_team, p.*, m.* FROM pokemon as p, movePoss as mp INNER JOIN move as m ON mp.id_move=m.id_move RIGHT JOIN team as t ON mp.id_team=t.id_team WHERE id_joueur= ? AND p.id_pokemon=t.id_pokemon ORDER BY t.id_team;', [joueur_id], (err, res2) => {
......@@ -219,24 +220,19 @@ function filterJSON(data, type){
if(dataSet.has(data[key]["id_pokemon"])) filteredData[i][moveNom].push(move);
else {i++;filteredData.push(temp); dataSet.add(data[key]["id_pokemon"]); filteredData[i][moveNom].push(move);}
});
//console.log(filteredData);
return filteredData;
}
function fuseJSON(dataUtil, dataPoss){
var fusedJSON = dataUtil;
//console.log(dataPoss);
//console.log(dataUtil);
Object.keys(fusedJSON).forEach(function(key) {
//console.log(key);
//console.log(dataPoss);
var tempTab = fusedJSON[key]["movesUtil"];
tempTab = tempTab.filter(value =>{
var contain = false;
dataPoss[key]["movesPoss"].forEach(value2 => {if(value.id_move == value2.id_move)contain = true});
return !contain;
});
console.log(tempTab);
//console.log(tempTab);
fusedJSON[key]["movesUtil"] = tempTab;
fusedJSON[key]["movesPoss"] = dataPoss[key]["movesPoss"];
});
......
This diff is collapsed.
......@@ -5,14 +5,16 @@
"main": "server.js",
"scripts": {
"start": "nodemon server.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"chai": "^4.2.0",
"express": "^4.17.1",
"express-session": "^1.17.1",
"mocha": "^8.0.1",
"mysql": "^2.18.1",
"nodemon": "^2.0.2",
"socket.io": "^2.3.0",
......
var assert = require('assert');
var chai = require("chai");
var expect = chai.expect;
var manip = require("../app/methods/JSONmanip");
let should = chai.should();
describe("JSON transformation", function () {
describe("JSON restructuring", function () {
it("removes duplicates and adds moves to the correct pokemon array", function () {
var data = [{
id_team: 53,
id_pokemon: 1,
pokeName: 'squirtle',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
id_move: 497,
identifier: 'echoed-voice',
description: '',
action: 0,
power: '40',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 1
},
{
id_team: 51,
id_pokemon: 4,
pokeName: 'charmander',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
id_move: 497,
identifier: 'echoed-voice',
description: '',
action: 0,
power: '40',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 1
},
{
id_team: 51,
id_pokemon: 4,
pokeName: 'charmander',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
id_move: 510,
identifier: 'incinerate',
description: '',
action: 0,
power: '60',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 10
},
{
id_team: 51,
id_pokemon: 4,
pokeName: 'charmander',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
id_move: 517,
identifier: 'inferno',
description: '',
action: 0,
power: '100',
pp: '5',
accuracy: '50',
priority: 0,
type_id: 10
}]
var result = [
{
id_team: 53,
id_pokemon: 1,
pokeName: 'squirtle',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
movesUtil: [{
id_move: 497,
identifier: 'echoed-voice',
description: '',
action: 0,
power: '40',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 1
}]
},
{
id_team: 51,
id_pokemon: 4,
pokeName: 'charmander',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
movesUtil: [{
id_move: 497,
identifier: 'echoed-voice',
description: '',
action: 0,
power: '40',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 1
}, {
id_move: 510,
identifier: 'incinerate',
description: '',
action: 0,
power: '60',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 10
}, {
id_move: 517,
identifier: 'inferno',
description: '',
action: 0,
power: '100',
pp: '5',
accuracy: '50',
priority: 0,
type_id: 10
}]
}]
var restructured = []
restructured = manip.filterJSON(data, true);
expect(restructured).to.deep.equal(result);
});
});
describe("JSON fusion", function () {
it("fuses two JSON and removes usable moves according to moves already in the possession of a pokemon", function () {
var data1 = [
{
id_team: 53,
id_pokemon: 1,
pokeName: 'squirtle',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
movesUtil: [{
id_move: 497,
identifier: 'echoed-voice',
description: '',
action: 0,
power: '40',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 1
}]
},
{
id_team: 51,
id_pokemon: 4,
pokeName: 'charmander',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
movesUtil: [{
id_move: 497,
identifier: 'echoed-voice',
description: '',
action: 0,
power: '40',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 1
}, {
id_move: 510,
identifier: 'incinerate',
description: '',
action: 0,
power: '60',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 10
}, {
id_move: 517,
identifier: 'inferno',
description: '',
action: 0,
power: '100',
pp: '5',
accuracy: '50',
priority: 0,
type_id: 10
}]
}];
var data2 = [
{
id_team: 53,
id_pokemon: 1,
pokeName: 'squirtle',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
movesPoss: [{
id_move: 497,
identifier: 'echoed-voice',
description: '',
action: 0,
power: '40',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 1
}]
},
{
id_team: 51,
id_pokemon: 4,
pokeName: 'charmander',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
movesPoss: [{
id_move: 497,
identifier: 'echoed-voice',
description: '',
action: 0,
power: '40',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 1
},{
id_move: 517,
identifier: 'inferno',
description: '',
action: 0,
power: '100',
pp: '5',
accuracy: '50',
priority: 0,
type_id: 10
}]
}]
result = [
{
id_team: 53,
id_pokemon: 1,
pokeName: 'squirtle',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
movesUtil: [],
movesPoss: [{
id_move: 497,
identifier: 'echoed-voice',
description: '',
action: 0,
power: '40',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 1
}]
},
{
id_team: 51,
id_pokemon: 4,
pokeName: 'charmander',
height: 6,
weight: 85,
base_experience: 62,
level: 0,
is_default: 1,
base_defense: 0,
base_attack: 0,
base_hp: 0,
id_type: 0,
movesUtil: [{
id_move: 510,
identifier: 'incinerate',
description: '',
action: 0,
power: '60',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 10
}],
movesPoss: [{
id_move: 497,
identifier: 'echoed-voice',
description: '',
action: 0,
power: '40',
pp: '15',
accuracy: '100',
priority: 0,
type_id: 1
}, {
id_move: 517,
identifier: 'inferno',
description: '',
action: 0,
power: '100',
pp: '5',
accuracy: '50',
priority: 0,
type_id: 10
}]
}];
var restructured = []
restructured = manip.fuseJSON(data1, data2);
expect(restructured).to.deep.equal(result);
});
});
});
\ No newline at end of file
import { TestBed, async } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import {HttpClientModule} from '@angular/common/http';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
......@@ -7,7 +11,8 @@ describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
RouterTestingModule,
HttpClientTestingModule
],
declarations: [
AppComponent
......
......@@ -4,8 +4,7 @@ import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule, HttpInterceptor, HttpRequest, HttpHandler,
HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';
import { ChatService } from './chat.service';
import { AccountSyncService } from "./services/account-sync/account-sync.service";
import { FormsModule } from '@angular/forms';
......@@ -51,7 +50,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
],
providers: [
ChatService,
AccountSyncService
AccountSyncService,
],
bootstrap: [AppComponent]
})
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BattleMenuComponent } from './battle-menu.component';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { HttpClientModule } from '@angular/common/http';
describe('BattleMenuComponent', () => {
let component: BattleMenuComponent;
......@@ -8,7 +10,8 @@ describe('BattleMenuComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BattleMenuComponent ]
declarations: [ BattleMenuComponent ],
imports: [HttpClientTestingModule]
})
.compileComponents();
}));
......
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { type } from 'os';
//import { type } from 'os';
@Component({
selector: 'app-battle',
......@@ -49,8 +49,7 @@ export class BattleComponent implements OnInit {
}
typeAdv(chiffMoi, chiffToi){
return 1
}
calculeDmg(){
......
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { HttpClientModule } from '@angular/common/http';
import { ChatService } from './chat.service';
describe('ChatService', () => {
let service: ChatService;
beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [ChatService]
});
service = TestBed.inject(ChatService);
});
......