import {J} from "../../utils"; import { ControllerTestData, ControllerTestFunc, ControllerNetwork } from "../types"; export type profileControllerTestData = { create$:ControllerTestData["profiles"]["create$"]; fetch$:ControllerTestData["profiles"]["fetch$"]; update$:ControllerTestData["profiles"]["update$"]; query$:ControllerTestData["profiles"]["query$"]; }; export const profileControllerTestData:profileControllerTestData = { create$:O => [ { body:{ name:O.users.john, role:"ADMIN", }, appuser:{ name:O.users.jack, device:O.devices.jack, okto:"use-api", next:"123456", role:"GUEST" as any, } },{ body:{ name:O.users.jim, role:"USER", }, appuser:{ name:O.users.jim, device:O.devices.jim, okto:"use-api", next:"123456", role:"GUEST" as any, } },{ body:{ name:O.users.jenn, role:"USER", }, appuser:{ name:O.users.jenn, device:O.devices.jenn, okto:"use-api", next:"123456", role:"GUEST" as any, } }, ], fetch$:O => [ { params:{id:O.jsons.profiles[0].id}, appuser:{ name:O.users.jack, device:O.devices.jack, okto:"use-api", next:"123456", role:"GUEST" as any, } },{ params:{name:O.jsons.profiles[1].name}, appuser:{ name:O.users.jim, device:O.devices.jim, okto:"use-api", next:"123456", role:"GUEST" as any, } }, ], update$:O => [ { params:{id:O.jsons.profiles[0].id}, body:{ $set:{ name:O.users.jack, status:{name:"Enabled",time:new Date()}, "settings.data":{...O.jsons.profiles[0].settings?.data,timeout:3600}, "settings.app.withBal":true, "settings.app.optionsOnly":true, "socials.fb":"boopscoop", "stats.views":17, "rating":4.8, "bio":"whatever whatevr whatevs", "motto":"No", }, $push:{ "activity":[ {name:"create-profile",time:new Date(),}, {name:"sent-message",time:new Date(),}, ], "followers":O.jsons.profiles[1].id, "following":[O.jsons.profiles[1].id], "endorsements":O.jsons.profiles[1].id, }, $pull:{"following":{$in:[O.jsons.profiles[1].id]},}, }, appuser:{ name:O.users.jack, device:O.devices.jack, okto:"use-api", next:"123456", role:"GUEST" as any, } },{ params:{id:O.jsons.profiles[1].id}, body:{ $set:{ status:{name:"Enabled" as any,time:new Date()}, "settings.data":{...O.jsons.profiles[1].settings?.data,timeout:3600}, "settings.app.withBal":true, "settings.app.optionsOnly":true, "socials.fb":"boopscoop", "stats.views":17, }, $push:{"following":[O.jsons.profiles[0].id],}, }, appuser:{ name:O.users.jim, device:O.devices.jim, okto:"use-api", next:"123456", role:"GUEST" as any, } },{ params:{id:O.jsons.profiles[2].id}, body:{ $set:{ status:{name:"Enabled" as any,time:new Date()}, "settings.data":{...O.jsons.profiles[2].settings?.data,timeout:3600}, "settings.app.withBal":true, "settings.app.optionsOnly":true, "socials.fb":"boopscoop", "stats.views":17, }, $push:{"following":[O.jsons.profiles[0].id],}, }, appuser:{ name:O.users.jenn, device:O.devices.jenn, okto:"use-api", next:"123456", role:"GUEST" as any, } }, ], query$:O => [ { query:{query:{name:O.users.jack},select:"json"}, appuser:{ name:O.users.jack, device:O.devices.jack, okto:"use-api", next:"123456", role:"GUEST" as any, } },{ query:{query:{name:O.users.john},select:"json"}, appuser:{ name:O.users.jack, device:O.devices.jack, okto:"use-api", next:"123456", role:"GUEST" as any, } },{ query:{query:{role:"USER"},select:"json"}, appuser:{ name:O.users.jack, device:O.devices.jack, okto:"use-api", next:"123456", role:"GUEST" as any, } }, ], }; export type profileControllerTests = { create$:ControllerTestFunc["profiles"]["create$"]; fetch$:ControllerTestFunc["profiles"]["fetch$"]; updateSetAndPush$:ControllerTestFunc["profiles"]["update$"]; updatePull$:ControllerTestFunc["profiles"]["update$"]; fetchFinal$:ControllerTestFunc["profiles"]["fetch$"]; query$:ControllerTestFunc["profiles"]["query$"]; }; export const profileControllerTests:profileControllerTests = { create$:async O => { const C = profileControllerTestData.create$(O); for(let i = 0,l = C.length;i { const F = profileControllerTestData.fetch$(O); for(let i = 0,l = F.length;i { const U = profileControllerTestData.update$(O); for(let i = 0,l = U.length;i { const U = profileControllerTestData.update$(O); for(let i = 0,l = U.length;i { const F = profileControllerTestData.fetch$(O); const {data:o} = await O.controllers.profiles.fetch$(F[0]); J.is(o); J.not(o,null); J.is(o.status?.name,"Enabled"); J.is(o.name,O.users.jack); J.is(o.role,"ADMIN"); //J.instance(o.permissions.cookies,Date); }, query$:async O => { const Q = profileControllerTestData.query$(O); for(let i = 0,l = Q.length;i J.desc("User Profiles",() => { it("Create",async () => await profileControllerTests.create$(O),1E9); it("Fetch",async () => await profileControllerTests.fetch$(O),1E9); it("Update - Set & Push",async () => await profileControllerTests.updateSetAndPush$(O),1E9); it("Update - Pull",async () => await profileControllerTests.updatePull$(O),1E9); it("Fetch - Final Check",async () => await profileControllerTests.fetchFinal$(O),1E9); it("Query",async () => await profileControllerTests.query$(O),1E9); });