Commit bfa197d1 authored by Walid Chafai's avatar Walid Chafai
Browse files

improve CafandFcCallback unit testing

parent b9eab3b5
......@@ -18,6 +18,10 @@ var fcData = {
given_name: "Eric",
sub: "3e7b92b9a94d96c6f3517aef4dfa1ef07c02f0a7e715c30c0fd72feae615b64dv1"
};
var FCdata = {
key : "fcData",
value : fcData
};
//define variable with parameters returned by apiParticulier DGFIP
var apiData = {
declarant1: {
......@@ -55,6 +59,11 @@ var data = {
numeroAllocataire: "0000354",
refService: "20002ABB63E1CA468A568CB461A4CAC7" //service with config fc and caf
};
var invalidData = {
codePostal: 45894798,
numeroAllocataire: "2584984",
refService: "4984984984"
};
var url = "/api/v1/caf/callback";
var token;
var ticketID = 0;
......@@ -123,10 +132,6 @@ describe("testing cafCallBack", function () {
beforeEach(function () {
this.timeout(5000);
var FCdata = {
key : "fcData",
value : fcData
};
var xhr_1 = new XMLHttpRequest();
xhr_1.open('POST', constatnte.uri+"/setSessionStorage");
xhr_1.setRequestHeader("Content-type","application/json;charset=UTF-8");
......@@ -151,6 +156,7 @@ describe("testing cafCallBack", function () {
data.codePostal = 99148;
data.numeroAllocataire = "0000354";
});
afterEach(function () {
token = currentSession().promoteWith(Constantes.agent);
if(ticketID == 0){
......
var constatnte = require("../../backend/modules/const.js");
describe("test CallBackFranceConnect", function () {
it("test callBack without parameters", function () {
var xhr = new XMLHttpRequest();
console.log("hamza");
xhr.open('GET', constatnte.uri+'/api/v1/fc/callback?code=9527e752aacc981115f498776a0bcf65654a32d1705b49be8ad900711216c14a&state=DED189B340A493459AB389A7C2E2664A');
xhr.onreadystatechange = function () {
if(this.readyState === XMLHttpRequest.DONE && this.status === 200) {
console.log(this.body);
}
};
xhr.send();
expect("5").equal(5);
});
});
\ No newline at end of file
var Constantes = require("../../backend/modules/const.js");
describe("test Collectivity methods", function () {
this.timeout(8000);
var collectivity;
var account;
var token;
var data = {
client_Id: "client_Id",
client_secret: "client_secret",
......@@ -13,7 +13,7 @@ describe("test Collectivity methods", function () {
};
describe("setClient method", function () {
var token;
beforeEach(function () {
token = currentSession().promoteWith(Constantes.admin);
collectivity = new ds.Collectivity();
......@@ -23,8 +23,7 @@ describe("test Collectivity methods", function () {
currentSession().unPromote(token);
token = currentSession().promoteWith(Constantes.superAdmin);
var col = ds.Collectivity.find("ID == :1", collectivity.ID);
if(col)
col.remove();
if(col) col.remove();
currentSession().unPromote(token);
});
......@@ -47,66 +46,113 @@ describe("test Collectivity methods", function () {
beforeEach(function () {
token = currentSession().promoteWith(Constantes.agent);
collectivity = new ds.Collectivity();
account = new ds.Account();
collectivity.name = data.name;
collectivity.active = false;
collectivity.save();
account.userName = "adress@mail.com";
account.collectivity = collectivity;
account.save();
var token = currentSession().promoteWith(Constantes.agent);
try{
collectivity = new ds.Collectivity();
account = new ds.Account();
collectivity.name = data.name;
collectivity.active = false;
collectivity.save();
account.userName = "adress@mail.com";
account.collectivity = collectivity;
account.save();
}
catch(error){
currentSession().unPromote(token);
}
finally{
currentSession().unPromote(token);
}
});
afterEach(function () {
currentSession().unPromote(token);
token = currentSession().promoteWith(Constantes.superAdmin);
var col = ds.Collectivity.find("ID == :1", collectivity.ID);
if(col)
col.remove();
var acc = ds.Account.find("ID == :1", account.ID);
if(acc)
acc.remove();
currentSession().unPromote(token);
var token = currentSession().promoteWith(Constantes.superAdmin);
try{
var col = ds.Collectivity.find("ID == :1", collectivity.ID);
if(col) col.remove();
var acc = ds.Account.find("ID == :1", account.ID);
if(acc) acc.remove();
}
catch(error){
currentSession().unPromote(token);
}
finally{
currentSession().unPromote(token);
}
});
it("validate request should pass", function () {
token = currentSession().promoteWith(Constantes.superAdmin);
var result = ds.Collectivity.valideRefuse(account.ID,collectivity.ID,"valide");
expect(result).to.be.an('object');
expect(result.status).equal(true);
expect(result.msg).equal("la demande est validée");
var token = currentSession().promoteWith(Constantes.superAdmin);
try{
var result = ds.Collectivity.valideRefuse(account.ID,collectivity.ID,"valide");
expect(result).to.be.an('object');
expect(result.status).equal(true);
expect(result.msg).equal("la demande est validée");
}
catch(error){
currentSession().unPromote(token);
}
finally{
currentSession().unPromote(token);
}
});
it("refuse request should pass", function () {
token = currentSession().promoteWith(Constantes.superAdmin);
var result = ds.Collectivity.valideRefuse(account.ID,collectivity.ID,"refuse");
expect(result).to.be.an('object');
expect(result.status).equal(true);
expect(result.msg).equal("la demande est refusé");
try{
var token = currentSession().promoteWith(Constantes.superAdmin);
var result = ds.Collectivity.valideRefuse(account.ID,collectivity.ID,"refuse");
expect(result).to.be.an('object');
expect(result.status).equal(true);
expect(result.msg).equal("la demande est refusé");
var token = currentSession().promoteWith(Constantes.superAdmin);
}
catch(error){
currentSession().unPromote(token);
}
currentSession().unPromote(token);
});
it("call function with null account and collectivity", function () {
token = currentSession().promoteWith(Constantes.superAdmin);
var result = ds.Collectivity.valideRefuse(null,null,"");
expect(result).to.be.an('object');
expect(result.status).equal(false);
expect(result.msg).equal("paramètre erroné");
var token = currentSession().promoteWith(Constantes.superAdmin);
try{
var result = ds.Collectivity.valideRefuse(null,null,"");
expect(result).to.be.an('object');
expect(result.status).equal(false);
expect(result.msg).equal("paramètre erroné");
}
catch(error){
currentSession().unPromote(token);
}
currentSession().unPromote(token);
});
it("call function with accountID and collectivityID doesn't existe", function () {
token = currentSession().promoteWith(Constantes.superAdmin);
var result = ds.Collectivity.valideRefuse(1010,1010,"");
expect(result).to.be.an('object');
expect(result.status).equal(false);
expect(result.msg).equal("compte n'existe pas");
var token = currentSession().promoteWith(Constantes.superAdmin);
try{
var result = ds.Collectivity.valideRefuse(1010,1010,"");
expect(result).to.be.an('object');
expect(result.status).equal(false);
expect(result.msg).equal("compte n'existe pas");
}
catch(error){
currentSession().unPromote(token);
}
currentSession().unPromote(token);
});
it("call function without define a operator", function () {
token = currentSession().promoteWith(Constantes.superAdmin);
var result = ds.Collectivity.valideRefuse(account.ID,collectivity.ID,"");
expect(result).to.be.an('object');
expect(result.status).equal(false);
var token = currentSession().promoteWith(Constantes.superAdmin);
try{
var result = ds.Collectivity.valideRefuse(account.ID,collectivity.ID,"");
expect(result).to.be.an('object');
expect(result.status).equal(false);
}
catch(error){
currentSession().unPromote(token);
}
currentSession().unPromote(token);
});
});
});
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment