var apx = apx || {};
apx.testapi = {};
apx.testapi.getdata={}
apx.testapi.getdata.home=()=>{return {}}


apx.testapi.deleteitm = async (tribe, objectname, apxid, primaryid) => {
    // example:  apx.testapi.deleteitm("smatchit","sirets","siret","91365310100018")
    const delitm = {
      method: "delete",
      url: `/api/apxtri/odmdb/itm/${tribe}/${objectname}/${apxid}/${primaryid}`,
      headers: apx.data.headers,
    };
    const delres = await axios(delitm);
    console.log(delres);
  };
  apx.testapi.getitm = async (tribe, objectname, primaryid) => {
    console.log('get ',`/api/apxtri/odmdb/itm/${tribe}/${objectname}/${primaryid}`)
    const getitm = {
      method: "get",
      url: `/api/apxtri/odmdb/itm/${tribe}/${objectname}/${primaryid}`,
      data: {},
      headers: apx.data.headers,
    };
    const repitm = await axios(getitm);
    if (repitm.status == 200) {
      if (!apx.data.itm) apx.data.itm = {};
      if (!apx.data.itm[objectname]) apx.data.itm[objectname] = {};
      apx.data.itm[objectname][primaryid] = repitm.data.data;
      apx.save();
      return repitm.data.data;
    } else {
      return repitm;
    }
  };
  
  apx.testapi.additm = async (tribe, objectname, data) => {
    const additm = {
      method: "post",
      url: `/api/apxtri/odmdb/itm/${tribe}/${objectname}`,
      data: data,
      headers: apx.data.headers,
    };
  
    return await axios(additm);
  };
  
  apx.testapi.testbase = async () => {
    console.log("run")
    //console.log(await apx.testapi.getitm("smatchit","seekers","philc"))
    //console.log(await apx.testapi.getitm("smatchit","persons","philc"))
    //console.log(await apx.testapi.getitm("smatchit","quizz","seekerknowhow_en"))
    const getinfo = await axios.put(
      `/api/smatchit/jobads/interviewers`,
      { jobstepids:["philc_f46b2d7e-e242-421f-802b-d8d4d02a2000_0"] },
      { headers: apx.data.headers }
    );
    console.log(getinfo);
    //await apx.testapi.deleteitm("smatchit","sirets","siret","34921281100021")
    //apx.testapi.testaddsiret();
    //apx.testapi.testgetlocaldb("smatchit","smatchapp","index","anonymous");
    //console.log(await apx.testapi.getitm("smatchit","quizz","seekermbti"))
  
    /*await apx.testapi.deleteitm(
      "smatchit",
      "jobads",
      "jobadid",
      "4570dadb-949b-4f6e-9d25-f389336055c1"
    );*/
    //apx.testapi.testaddjobads("4570dadb-949b-4f6e-9d25-f389336055c6");
    //this include jobad matching
    //apx.testapi.testpublish("4570dadb-949b-4f6e-9d25-f389336055c6");
  
    //apx.testapi.testunpublish("4570dadb-949b-4f6e-9d25-f389336055ca")
    //apx.testapi.testseekerinfoforecruiter(["13cdd66c-7a22-470c-b3c9-0ba1589a1db8"],"philc")
    // test jobsteps process
    //refresh user data apx.testapi.getItem
    //match jobads to currentuser:
    /*apx.testapi.testseekerjobstepprocess(
      apx.data.headers.xalias,
      "4570dadb-949b-4f6e-9d25-f389336055c5"
    );
    */
    //connected as a seeker run to apply:
    //apx.testapi.testjobstepsstateapply("4570dadb-949b-4f6e-9d25-f389336055c5");
  
    //apx.testapi.testnotificationsendmail(["phc@ndda.fr"],"requestregistration",{email:"phc@ndda.fr",firstname:"phil", lastname:"coco"})
    //apx.testapi.testseekeronboardingmatching("philc")
    //apx.testapi.testbooking({ date: "2024-08-01", start: "08:30", numberofslot: 2 });
    /*await apx.testapi.invitedtoapply(
      "paulseek",
      "4570dadb-949b-4f6e-9d25-f389336055c2",
      "philc"
    );*/
    //apx.testapi.testrecruiteremailtoalias();
  };
  apx.testapi.testrecruiteremailtoalias = () => {
    console.log(
      "you must be a recruiter to run this request, it add alias to jobsteps where it is empty"
    );
    axios.get("/api/smatchit/recruiters/emailtoaliasjobstep", {
        headers: apx.data.headers,
      })
      .then((rep) => console.log(rep))
      .catch((err) => {
        console.log(err);
      });
  };
  apx.testapi.invitedtoapply = (seeker, jobadid) => {
    axios
      .put(
        "/api/smatchit/jobads/invitedtoapply",
        { seeker: seeker, jobadid: jobadid },
        { headers: apx.data.headers }
      )
      .then((rep) => console.log(rep))
      .catch((err) => {
        console.log(err);
      });
  };
  apx.testapi.testseekerjobstepprocess = (seeker, jobadid) => {
    console.log('charge seeker info"');
    //check in seeker jobadmatchscore the jobadid exist
    apx.testapi.getitm("smatchit", "persons", seeker);
    if (!apx.data.headers.xprofils.includes("seekers")) {
      alert("Sorry must be a seeker to apply");
      return false;
    }
    apx.testapi.getitm("smatchit", "seekers", seeker);
    //await apx.testapi.testseekeronboardingmatching(seeker);
  };
  
  apx.testapi.testbook = () => {
    const test = {
      availableslot: {
        "2024-08-10": {
          "08:00": "D",
          "08:30": "D",
          "09:00": "D",
          "09:30": "D",
          "10:00": "D",
          "10:30": "D",
          "11:00": "D",
          "11:30": "D",
          "12:00": "D",
          "12:30": "D",
          "13:00": "D",
          "13:30": "D",
          "14:00": "D",
          "14:30": "D",
          "15:00": "D",
          "15:30": "D",
          "16:00": "D",
          "16:30": "D",
          "17:00": "D",
          "17:30": "D",
          "18:00": "D",
          "18:30": "D",
          "19:00": "D",
        },
        "2024-08-11": {
          "08:00": "D",
          "08:30": "D",
          "09:00": "D",
          "09:30": "D",
          "10:00": "D",
          "10:30": "D",
          "11:00": "D",
          "11:30": "D",
          "12:00": "D",
          "12:30": "D",
          "13:00": "D",
          "13:30": "D",
          "14:00": "D",
          "14:30": "D",
          "15:00": "D",
          "15:30": "D",
          "16:00": "D",
          "16:30": "D",
          "17:00": "D",
          "17:30": "D",
          "18:00": "D",
          "18:30": "D",
          "19:00": "D",
        },
      },
    };
    console.log(test.availableslot && Object.keys(test.availableslot).length > 0);
    if (
      test.availableslot &&
      Object.keys(test.availableslot).length > 0 &&
      dayjs(Object.keys(test.availableslot).sort()[0]) > dayjs()
    ) {
      console.log("PASSe etape act.interviewersetjobstep");
    } else {
      console.log("passe pas");
    }
    const s = { date: "2024-08-12", start: "08:00" };
    console.log(
      dayjs(`${s.date} ${s.start}`)
        .add(30 * 2, "minutes")
        .format("HH:mm")
    );
  };
  
  apx.testapi.testbooking = (slottime) => {
    const tirage = (probabilites) => {
      //distribution {A:0.7,B:0.3} return in 70% A else B
      const entries = Object.entries(probabilites);
      const cumulativeProbabilities = entries.reduce((acc, [value, prob]) => {
        const prevProb = acc.length > 0 ? acc[acc.length - 1][1] : 0;
        return [...acc, [value, prevProb + prob]];
      }, []);
      const random = Math.random();
      return cumulativeProbabilities.find(([value, prob]) => random < prob)[0];
    };
    const getlistslottime = (startslot, endslot, interval) => {
      const timearray = [];
      let encours = dayjs("2020-01-01 " + startslot);
      const end = dayjs("2020-01-01 " + endslot);
      console.log(encours);
      console.log(end);
      console.log(encours.isBefore(end));
      while (encours.isBefore(end)) {
        timearray.push(encours.format("HH:mm"));
        encours = encours.add(interval, "minutes");
      }
      return timearray;
    };
    const simuleinterviewer = (interviewer) => {
      // const interviewer = {startslot: "08:00",endslot: "17:00",interval: 30, availableslot: {}, };
      // set futur
      const arraytime = getlistslottime(
        interviewer.startslot,
        interviewer.endslot,
        interviewer.interval
      );
      for (let i = 1; i < 3; i++) {
        const newd = dayjs().add(i, "days").format("YYYY-MM-DD");
        interviewer.availableslot[newd] = {};
        arraytime.forEach(
          (t) => (interviewer.availableslot[newd][t] = tirage({ F: 0.7, D: 0.3 }))
        );
      }
      return interviewer;
    };
    //simule un agenda
    //console.log(simuleinterviewer({startslot: "08:00",endslot: "17:00",interval: 30, availableslot: {} }))
  
    const interviewer = {
      startslot: "08:00",
      endslot: "17:00",
      interval: 30,
      availableslot: {
        "2024-07-31": {
          "08:00": "F",
          "08:30": "F",
          "09:00": "F",
          "09:30": "F",
          "10:00": "D",
          "10:30": "D",
          "11:00": "F",
          "11:30": "D",
          "12:00": "F",
          "12:30": "F",
          "13:00": "D",
          "13:30": "F",
          "14:00": "D",
          "14:30": "F",
          "15:00": "F",
          "15:30": "D",
          "16:00": "D",
          "16:30": "D",
        },
        "2024-08-01": {
          "08:00": "F",
          "08:30": "F",
          "09:00": "F",
          "09:30": "D",
          "10:00": "F",
          "10:30": "F",
          "11:00": "F",
          "11:30": "D",
          "12:00": "D",
          "12:30": "F",
          "13:00": "F",
          "13:30": "D",
          "14:00": "F",
          "14:30": "D",
          "15:00": "F",
          "15:30": "F",
          "16:00": "F",
          "16:30": "F",
        },
      },
    };
    //{ date: "2024-08-01", start: "08:30", numberofslot: 2 }
    let matchslottime = true;
    matchslottime = interviewer.availableslot[slottime.date] ? true : false;
    matchslottime = interviewer.availableslot[slottime.date][slottime.start]
      ? true
      : false;
    matchslottime =
      interviewer.availableslot[slottime.date][slottime.start] == "F";
    let slottobook = [slottime.start];
    console.log("1er slot:", matchslottime);
    if (matchslottime) {
      const slotarray = Object.keys(
        interviewer.availableslot[slottime.date]
      ).sort();
      console.log(slotarray);
      for (
        i = slotarray.indexOf(slottime.start) + 1;
        i < slottime.numberofslot + 1;
        i++
      ) {
        matchslottime = interviewer.availableslot[slottime.date][i] != "F";
        slottobook.push(slotarray[i]);
      }
    }
    console.log(slottobook);
    if (matchslottime) {
      slottobook.forEach((t) => {
        interviewer.availableslot[slottime.date][t] = "J";
      });
      console.log("booking", interviewer.availableslot[slottime.date]);
    } else {
      console.log("no booking:");
    }
  };
  
  apx.testapi.testseekeronboardingmatching = async (seeker) => {
    await axios
      .get(`/api/smatchit/seekers/onboarding/${seeker}`, {
        headers: apx.data.headers,
      })
      .then((rep) => {
        //alert("success, check console");
        console.log(rep);
      })
      .catch((err) => {
        //alert("err, check console");
        console.log(err);
      });
  };
  
  apx.testapi.testnotificationsendmail = async (emails, template, data) => {
    await axios
      .post(
        `/api/apxtri/notifications/sendmail/smatchit/${template}`,
        { emails, data },
        { headers: apx.data.headers }
      )
      .then((rep) => {
        alert("success, check console");
        console.log(rep);
      })
      .catch((err) => {
        alert("err, check console");
        console.log(err);
      });
  };
  
  apx.testapi.testseekerinfoforecruiter = async (jobadids, aliasrecruiter) => {
    // must be connectered as aliasrecruitrer or to have adminrecruiter profil for the same siret than jobads
    await axios
      .put(
        `/api/smatchit/seekers/infoseeker/${aliasrecruiter}`,
        { jobadids: jobadids },
        { headers: apx.data.headers }
      )
      .then((rep) => {
        alert("success, check console");
        console.log(rep);
      })
      .catch((err) => {
        alert("err, check console");
        console.log(err);
      });
  };
  apx.testapi.testjobstepsstateapply = async (jobadid) => {
    //create a jobstep
    console.log("getitm");
    const jobad = await apx.testapi.getitm("smatchit", "jobads", jobadid);
    if (jobad.status) {
      console.log("issue to get jobad", getjobad);
    }
    console.log(jobad);
    const jobstep = {
      jobadid: jobadid,
      recruiter: jobad.recruiter,
      interviewer: jobad.jobsteps[0].interviewer,
      jobstepid: `${apx.data.headers.xalias}_${jobadid}_0`,
      seeker: apx.data.headers.xalias,
      state: "apply",
    };
    console.log(jobstep);
    //const apply = await apx.testapi.additm("smatchit", "jobsteps", jobstep);
    //console.log(apply);
    console.log(`/api/smatchit/jobads/jobstepstodo/${jobstep.jobstepid}`);
    const jobstepstodo = await axios.put(
      `/api/smatchit/jobads/jobstepstodo/${jobstep.jobstepid}`,
      { state: "apply" },
      { headers: apx.data.headers }
    );
    console.log(jobstepstodo);
  };
  
  apx.testapi.testunpublish = async (jobadid) => {
    await axios
      .put(
        `/api/smatchit/jobads/archive/${jobadid}`,
        {},
        { headers: apx.data.headers }
      )
      .then((rep) => {
        alert("success, check console");
        console.log(rep);
      })
      .catch((err) => {
        alert("err, check console");
        console.log(err);
      });
  };
  apx.testapi.testpublish = async (jobadid) => {
    await axios
      .put(
        `/api/smatchit/jobads/publish/${jobadid}`,
        {},
        { headers: apx.data.headers }
      )
      .then((rep) => {
        //alert("success, check console");
        console.log(rep);
      })
      .catch((err) => {
        //alert("err, check console");
        console.log(err);
      });
  };
  
  apx.testapi.testaddjobads = (jobadid) => {
    /*const jobad = {
      jobadid: jobadid,
      state: "inprocess",
      siret: "34921281100021",
      category: "gaming",
      jobtitle: "cuisinier",
      jobdisplayname: "Cuisinier poissonier",
      contactrecruiter: "philc",
      state: "draft",
      recruiter: "philc",
      jobadtitle: "Cuisinier poissonier",
      candidateexperience: "4to12",
      specificskills: {
        reserveeventticket: 2,
        teamcoordination: 3,
        aftersellservice: 2,
      },
      languageskills: {
        french: 4,
        english: 2,
      },
      knowhows: ["service", "reactif", "inspire"],
      dealbreaker: ["ponctualitty"],
      jobtype: ["cdi", "cdd", "interim", "freelance", "stage", "alternance"],
      fulltime: "fullandpartial",
      remote: 100,
      workingdayshours: [
        {
          day: "Tuesday",
          hours: [
            { start: "09:00", end: "00:00" },
            { start: "11:00", end: "00:00" },
          ],
        },
      ],
      salary: 100000,
      salarydevise: "€",
      salaryunit: "peryear",
      jobsteps: [
        {
          jobsteptype: "firstcontact",
          interviewer: "philc",
        },
        {
          jobsteptype: "testaptitude",
          interviewer: "interviewerpeter",
        },
        {
          jobsteptype: "interview",
          interviewer: "philc",
        },
      ],
      description:
        "Hello, About Job \\nLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
    };*/
    const jobad = {
      jobadid: jobadid,
      state: "publish",
      siret: "42818175400014",
      category: "Automobile",
      jobtitle: "vendorretail",
      jobdisplayname: "Épicière",
      jobadtitle: "Épicière Test",
      candidateexperience: "12to15",
      specificskills: {
        productvalidity: 3,
        trackproduct: 1,
        informclient: 1,
        chooseintervention: 0,
        reserveeventticket: 2,
        teamcoordination: 3,
        aftersellservice: 3,
        adaptsellstrategy: 3,
        createsellarguments: 3,
        technicalexpertise: 3,
        instructemployee: 3,
        deliverorder: 3,
      },
      knowhows: ["teamwork", "accurate", "service", "listening", "fits"],
      dealbreaker: ["ponctualitty"],
      languageskills: {
        french: 4,
        english: 1,
      },
      jobtype: ["cdi", "freelance", "stage"],
      fulltime: "full",
      remote: 50,
      workingdayshours: [
        {
          day: "Tuesday",
          hours: [
            {
              start: "10",
              end: "00",
            },
            {
              start: "19",
              end: "00",
            },
          ],
        },
      ],
      salary: 100000,
      salarydevise: "€",
      salaryunit: "permonth",
      jobsteps: [
        {
          jobsteptype: "firstcontact",
          interviewer: "philc",
          email: "smatchitdev@mailsac.com",
        },
        {
          jobsteptype: "testaptitude",
          interviewer: "philc",
          email: "smatchitdev@mailsac.com",
        },
        {
          jobsteptype: "interview",
          interviewer: "philc",
          email: "smatchitdev@mailsac.com",
        },
        {
          jobsteptype: "call",
          interviewer: "philc",
          email: "smatchitdev@mailsac.com",
        },
      ],
      description:
        'Contrary to popular belief, Lorem Ipsum is not simply random text. It is rooted in a piece of classical Latin literature from 45 BC, over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, trendy during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.',
      recruiter: "philc",
      urgenthiring: false,
      jobadmbti: "",
      jobadlocation: [],
      critrulesalary: "",
      owner: "philc",
      dt_create: "2024-08-02T06:22:25.720Z",
    };
    console.log(apx.testapi.additm("smatchit", "jobads", jobad));
  };
  
  apx.testapi.testaddsiret = () => {
    const siret = {
      siret: "34921281100021",
      businessname: "SAAS",
      code_naf: "92.3H",
      tradename: "SAAS",
      category: "gaming",
      billinglocation: {
        type: "housenumber",
        housenumber: "25",
        street: "Rue de Ponthieu",
        name: "25 Rue de Ponthieu",
        label: "25 Rue de Ponthieu 75008 Paris",
        postcode: "75008",
        citycode: "75108",
        city: "Paris",
        position: {
          properties: { longitude: 2.309055, latitude: 48.870756 },
        },
        context: "75, Paris, Île-de-France",
      },
      businesslocation: {
        type: "housenumber",
        housenumber: "25",
        street: "Rue de Ponthieu",
        name: "25 Rue de Ponthieu",
        label: "25 Rue de Ponthieu 75008 Paris",
        postcode: "75008",
        citycode: "75108",
        city: "Paris",
        position: {
          properties: { longitude: 2.309055, latitude: 48.870756 },
        },
        context: "75, Paris, Île-de-France",
      },
      website: "https://www.google.com",
      socialnetworks: ["abcd"],
      title: "Hello Compnay",
      description: "lets good  👍 ",
      agreetorespectnorms: true,
    };
    const addsiret = {
      method: "post",
      url: `/api/apxtri/odmdb/itm/smatchit/sirets`,
      data: siret,
      headers: apx.data.headers,
    };
    axios(addsiret)
      .then((rep) => {
        alert("success, check console");
        console.log(rep);
      })
      .catch((err) => {
        alert("err, check console");
        console.log(err);
      });
  };
  
  apx.testapi.testdeviceid = () => {
    function test() {
      if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
        alert("enumerateDevices() not supported.");
        return;
      }
  
      // List cameras and microphones.
  
      navigator.mediaDevices
        .enumerateDevices()
        .then(function (devices) {
          devices.forEach(function (device) {
            alert(device.kind + ": " + device.label + " id = " + device.deviceId);
          });
        })
        .catch(function (err) {
          alert(err.name + ": " + err.message);
        });
    }
    test();
  };
  
  apx.testapi.testdeletealias = async () => {
    const aliastodel = ["totopoursup"];
    aliastodel.forEach((a) => {
      const axiosdel = {
        method: "delete",
        url: `/api/apxtri/pagans/person/smatchit/${a}`,
        data: newseeker,
        headers: apx.data.headers,
      };
      axios(axiosdel)
        .then((rep) => {
          alert("success, check console");
          console.log(rep);
        })
        .catch((err) => {
          alert("err, check console");
          console.log(err);
        });
    });
  };
  
  apx.testapi.testaddseeker = async () => {
    const newseeker = {
      alias: "philc",
      email: "bhavesh@mailsac.com",
      locationenabled: true,
      notificationenabled: true,
      seekstatus: "notlooking",
      seekworkingyear: "4to8",
      seekjobtitleexperience: ["chefpartie"],
      seeklocation: [
        {
          type: "street",
          housenumber: "",
          street: "Igny",
          name: "Igny",
          label: "Igny 18200 La Perche",
          postcode: "18200",
          citycode: "18178",
          city: "La Perche",
          zoning: 3,
          position: { properties: { longitude: 2.585915, latitude: 46.638536 } },
          context: "18, Cher, Centre-Val de Loire",
        },
      ],
      salaryexpectation: "2331",
      salaryunit: "permonth",
      salarydevise: "€",
      mbti: { E: 1, N: 3, T: 0, nextq: 4, value: "INFP" },
    };
    const axiosaddseeker = {
      method: "post",
      url: `/api/apxtri/odmdb/itm/smatchit/seekers`,
      data: newseeker,
      headers: apx.data.headers,
    };
    const addseek = await axios(axiosaddseeker);
    console.log("profil update", addseek);
  };
  
  apx.testapi.testremoveprofilrecruiter = async () => {
    const user = "philc";
    const axiosgetperson = {
      method: "delete",
      url: `/api/smatchit/persons/recruiters/${user}`,
      headers: apx.data.headers,
    };
    const axiosaddrecruiters = {
      method: "put",
      url: `/api/apxtri/pagans/person/smatchit`,
      data: { addprofils: "recruiters", alias: user },
      headers: apx.data.headers,
    };
    const addrec = await axios(axiosaddrecruiters);
    console.log("profil update", addrec);
    const axiosperson = await axios(axiosgetperson);
    if (axiosperson.status != 200) {
      console.log("erreur getting person");
      return false;
    } else {
      console.log("lecture person", axiosperson);
    }
  };
  
  apx.testapi.testaddprofilrecruiter = async () => {
    const user = "philc";
    const axiosgetperson = {
      method: "get",
      url: `/api/apxtri/odmdb/itm/smatchit/persons/${user}`,
      headers: apx.data.headers,
    };
    const axiosaddrecruiters = {
      method: "put",
      url: `/api/apxtri/pagans/person/smatchit`,
      data: { addprofils: "recruiters", alias: user },
      headers: apx.data.headers,
    };
    const addrec = await axios(axiosaddrecruiters);
    console.log("profil update", addrec);
    const axiosperson = await axios(axiosgetperson);
    if (axiosperson.status != 200) {
      console.log("erreur getting person");
      return false;
    } else {
      console.log("lecture person", axiosperson);
    }
  };
  apx.testapi.testseekerprofil = async () => {
    alert("get person and modify ");
    //get a person
    const user = "philc";
    const axiosgetperson = {
      method: "get",
      url: `/api/apxtri/odmdb/itm/smatchit/persons/${user}`,
      headers: apx.data.headers,
    };
    const axiosputperson = {
      method: "put",
      url: `/api/apxtri/odmdb/itm/smatchit/persons/`,
      data: {},
      headers: apx.data.headers,
    };
    let userperson;
    const axiosperson = await axios(axiosgetperson);
    if (axiosperson.status != 200) {
      console.log("erreur getting person");
      return false;
    }
    userperson = axiosperson.data.data;
    console.log(userperson);
    let updateperson = {
      alias: user,
      firebaseid: userperson.firebaseid + "test",
      profils: ["seekers"],
    };
    axiosputperson.data = updateperson;
    console.log(axiosputperson);
    const axiosupdateperson = await axios(axiosputperson);
    console.log("modification done", axiosupdateperson);
    //alert("change again to remove test in firebase");
    updateperson = {
      alias: user,
      firebaseid: userperson.firebaseid.replace(/test/g, ""),
    };
    axiosputperson.data = updateperson;
    console.log(axiosputperson);
    const axiosupdatepersonback = await axios(axiosputperson);
    console.log(axiosupdatepersonback);
  };
  apx.testapi.testgetlocaldb = (tribe, appname, pagename, anonymous) => {
    const testaxios = {
      method: "get",
      url: `/api/apxtri/wwws/updatelocaldb${anonymous}/${tribe}/${appname}/${pagename}/0`,
      headers: apx.data.headers,
    };
  
    axios(testaxios)
      .then((rep) => {
        alert("success, check console");
        console.log(rep);
      })
      .catch((err) => {
        alert("err, check console");
        console.log(err);
      });
  };
  
  apx.testapi.testgetperson = () => {
    const testaxios = {
      method: "get",
      url: `/api/apxtri/odmdb/itm/${apx.data.headers.xtribe}/persons/philc`,
      headers: apx.data.headers,
    };
  
    axios(testaxios)
      .then((rep) => {
        alert("success, check console");
        console.log(rep);
      })
      .catch((err) => {
        alert("err, check console");
        console.log(err);
      });
  };
  
  apx.testapi.testupdateseeker = () => {
    apx.data.itm.seekers.jobadinvitedtoapply = [
      "f46b2d7e-e242-421f-802b-d8d4d02a2004",
    ];
    const testaxios = {
      method: "put",
      url: `/api/apxtri/odmdb/itm/${apx.data.headers.xtribe}/seekers`,
      data: apx.data.itm.seekers,
      headers: apx.data.headers,
    };
  
    axios(testaxios)
      .then((rep) => {
        alert("success, check console");
        console.log(rep);
      })
      .catch((err) => {
        alert("err, check console");
        console.log(err);
      });
  };
  
  apx.testapi.testbackend = () => {
    const objsearch = {
      apxid: [
        "f46b2d7e-e242-421f-802b-d8d4d02a2000",
        "f46b2d7e-e242-421f-802b-d8d4d02a2001",
        "f46b2d7e-e242-421f-802b-d8d4d02a2002",
        "f46b2d7e-e242-421f-802b-d8d4d02a2003",
      ],
      fields: "all",
    };
    const objsearchaxios = {
      method: "post",
      url: `/api/apxtri/odmdb/searchitms/${apx.data.headers.xtribe}/jobads`,
      data: objsearch,
      headers: apx.data.headers,
    };
  
    axios(objsearchaxios)
      .then((rep) => {
        alert("success, check console");
        console.log(rep);
      })
      .catch((err) => {
        alert("err, check console");
        console.log(err);
      });
  };
  /*
  apx.testapi.apxlocal = {};
  apx.testapi.apxlocal.setup = () => {
    console.log("run apxlocal.setup");
    apx.data.tpldata.apxlocal.categories.forEach((cat, i) => {
      //Object.keys(apx.data[cat.categorie]).forEach((o)=>{apx.data.tpldata.apxlocal.categories[i].list=[]})
      Object.keys(apx.data[cat.categorie]).forEach((o) => {
        if (!apx.data.tpldata.apxlocal.categories[i].list.includes(o)) {
          apx.data.tpldata.apxlocal.categories[i].list.push(o);
        }
      });
    });
    document
      .getElementsByName("apxlocal")
      .forEach(
        (e) =>
          (e.innerHTML = Mustache.render(
            apx.data.tpl.apxlocal,
            apx.data.tpldata.apxlocal
          ))
      );
    dscreen.refresh();
  };
  apx.readyafterupdate(apx.testapi.apxlocal.setup);
  */