1var F=Object.defineProperty;var D=(d,t,s)=>t in d?F(d,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):d[t]=s;var A=(d,t,s)=>D(d,typeof t!="symbol"?t+"":t,s);var c=(d,t,s)=>new Promise((a,r)=>{var o=h=>{try{m(s.next(h))}catch(x){r(x)}},n=h=>{try{m(s.throw(h))}catch(x){r(x)}},m=h=>h.done?a(h.value):Promise.resolve(h.value).then(o,n);m((s=s.apply(d,t)).next())});import{s as l,r as P,u as _,j as e,C as y,e as w,f as j,B as T,d as p,T as S}from"./index-CM31LsXv.js";import{B as C}from"./badge-DHVqVuRB.js";import{a as q,S as B}from"./authSecurityTestRunner-B0irXBIU.js";import{P as v}from"./products-_8pON4xh.js";import{A as f}from"./analytics-h86k6niM.js";import{r as k}from"./routeTestRunner-vTy_Ix92.js";import{Z as M}from"./zap-DPMBjyCW.js";import{P as $}from"./play-BoiwzrM6.js";import{R as K}from"./rotate-ccw-SeBWUWQI.js";import{C as U}from"./circle-x-Ci9BT4NP.js";import{C as H}from"./circle-check-big-6W0IiBa1.js";import"./base-B6uAFjZg.js";class L{constructor(){A(this,"results",[])}runTest(t,s,a){return c(this,null,function*(){const r=Date.now();try{yield s();const o=Date.now()-r,n={name:t,status:"passed",message:"Integration test passed",duration:o,category:a};return this.results.push(n),n}catch(o){const n=Date.now()-r,m=o instanceof Error?o.message:String(o),h={name:t,status:"failed",message:m,duration:n,category:a,details:o};return this.results.push(h),h}})}testAuthenticationIntegration(){return c(this,null,function*(){yield this.runTest("Authentication Security Fixes Integration",()=>c(this,null,function*(){const s=(yield q.runAllSecurityTests()).filter(a=>a.securityLevel==="critical"&&a.status==="failed");if(s.length>0)throw new Error(`Critical security issues found: ${s.length}`)}),"authentication"),yield this.runTest("Session Management Integration",()=>c(this,null,function*(){const t=yield B.getSessionInfo();if(t.isActive){if(!t.user||!t.expiresAt)throw new Error("Active session missing required data");const s=new Date(t.expiresAt).getTime();if(Date.now()>=s)throw new Error("Session reported as active but is expired")}}),"authentication"),yield this.runTest("Navigation Security Integration",()=>c(this,null,function*(){const{data:{session:t}}=yield l.auth.getSession();if(t){const{data:s,error:a}=yield l.from("user_profiles").select("id, role, status").eq("id",t.user.id).single();if(a)throw new Error("Authenticated user missing profile");if(!s.role)throw new Error("User profile missing role");if(s.status!=="active")throw new Error("Inactive user has active session")}}),"security")})}testAPIIntegration(){return c(this,null,function*(){yield this.runTest("Enhanced BaseAPI Integration",()=>c(this,null,function*(){const t=yield v.getCategories();if(!Array.isArray(t))throw new Error("ProductsAPI.getCategories should return array")}),"api"),yield this.runTest("Products API Build Fix Integration",()=>c(this,null,function*(){const t=yield v.getProducts({active:!0});if(!Array.isArray(t))throw new Error("ProductsAPI.getProducts should return array");const s=yield v.getCatalogProducts({active:!0});if(!Array.isArray(s))throw new Error("ProductsAPI.getCatalogProducts should return array");s.forEach(a=>{if(typeof a.in_cart!="boolean")throw new Error("Product missing in_cart field");if(typeof a.cart_quantity!="number")throw new Error("Product missing cart_quantity field")})}),"api"),yield this.runTest("Analytics API Schema Fix Integration",()=>c(this,null,function*(){const{data:{session:t}}=yield l.auth.getSession();if(t){const{data:s}=yield l.from("user_profiles").select("role").eq("id",t.user.id).single();if((s==null?void 0:s.role)==="franchisor"){const a=yield f.getFranchisorAnalytics();if(!a.overview||!a.performance||!a.financial)throw new Error("Franchisor analytics missing required sections")}else if((s==null?void 0:s.role)==="franchisee"){const{data:a}=yield l.from("franchise_locations").select("id").eq("franchisee_id",t.user.id).limit(1);if(a&&a.length>0){const r=yield f.getFranchiseeAnalytics(a[0].id);if(!r.sales||!r.orders||!r.inventory)throw new Error("Franchisee analytics missing required sections")}}}}),"api")})}testRoutingIntegration(){return c(this,null,function*(){yield this.runTest("Route Component Loading Integration",()=>c(this,null,function*(){const s=(yield k.runAllRouteTests()).filter(a=>a.status==="error");
1if(s.length>0)throw new Error(`${s.length} routes failed to load`)}),"routing"),yield this.runTest("Protected Route Security Integration",()=>c(this,null,function*(){const{data:{session:t}}=yield l.auth.getSession();if(!t){const{data:s,error:a}=yield l.from("orders").select("*").limit(1);if(s&&s.length>0)throw new Error("Unauthenticated user can access protected data");if(!a||!a.message.includes("JWT"))throw new Error("Protected data should require authentication")}}),"security")})}testDashboardIntegration(){return c(this,null,function*(){yield this.runTest("Dashboard Widget Data Loading Integration",()=>c(this,null,function*(){const{data:{session:t}}=yield l.auth.getSession();if(t){const{data:s}=yield l.from("user_profiles").select("role").eq("id",t.user.id).single();if((s==null?void 0:s.role)==="franchisor"){const a=yield f.getFranchisorMetrics(t.user.id);if(!a||typeof a!="object")throw new Error("Franchisor metrics should return object");if(!a.overview||!a.performance||!a.financial)throw new Error("Franchisor metrics missing required sections")}else if((s==null?void 0:s.role)==="franchisee"){const{data:a}=yield l.from("franchise_locations").select("id").eq("franchisee_id",t.user.id).limit(1);if(a&&a.length>0){const r=yield f.getFranchiseeMetrics(a[0].id);if(!r||typeof r!="object")throw new Error("Franchisee metrics should return object");if(!r.sales||!r.orders||!r.inventory||!r.performance)throw new Error("Franchisee metrics missing required sections")}}}}),"dashboard"),yield this.runTest("KPI Cards Access Control Integration",()=>c(this,null,function*(){const{data:{session:t}}=yield l.auth.getSession();if(t){const{data:s}=yield l.from("user_profiles").select("role").eq("id",t.user.id).single();if((s==null?void 0:s.role)==="franchisee"){const{data:a}=yield l.from("franchise_locations").select("id").eq("franchisee_id",t.user.id).limit(1);if(a&&a.length>0){const r=yield f.getKPIMetrics(a[0].id);if(!r||typeof r!="object")throw new Error("KPI metrics should return object");const o=["todaySales","weekSales","monthSales","salesChange","orderCount","avgOrderValue","inventoryValue","lowStockItems"];for(const n of o)if(typeof r[n]!="number")throw new Error(`KPI metrics missing required field: ${n}`)}}}}),"dashboard"),yield this.runTest("Real Data vs Mock Data Validation",()=>c(this,null,function*(){const{data:{session:t}}=yield l.auth.getSession();if(t){const{data:s}=yield l.from("user_profiles").select("role").eq("id",t.user.id).single();if((s==null?void 0:s.role)==="franchisee"){const{data:a}=yield l.from("franchise_locations").select("id").eq("franchisee_id",t.user.id).limit(1);if(a&&a.length>0){const r=yield f.getFranchiseeAnalytics(a[0].id);if(r.insights&&r.insights.length>0){const o=r.insights.some(n=>n.includes("All systems operating normally"));r.insights.length===1&&o&&console.warn("Dashboard may be using fallback data - no specific insights generated")}}}}}),"dashboard")})}testSystemHealthIntegration(){return c(this,null,function*(){yield this.runTest("Database Connection Health",()=>c(this,null,function*(){const{data:t,error:s}=yield l.from("user_profiles").select("count").limit(1);if(s)throw new Error(`Database connection failed: ${s.message}`)}),"api"),yield this.runTest("Error Boundary Integration",()=>c(this,null,function*(){try{yield v.getProductById("non-existent-id-12345")}catch(t){if(!t.code||!t.message)throw new Error("API errors should have proper error codes and messages")}}),"api"),yield this.runTest("Performance Monitoring Integration",()=>c(this,null,function*(){const t=Date.now();yield v.getCategories();const s=Date.now()-t;if(s>5e3)throw new Error(`API call took too long: ${s}ms`)}),"api")})}runAllIntegrationTests(){return c(this,null,function*(){return this.results=[],console.log("ð Starting Comprehensive Integration Tests..."),yield this.testAuthenticationIntegration(),yield this.testAPIIntegration(),yield this.testRoutingIntegration(),yield this.testDashboardIntegration(),yield this.testSystemHealthIntegration(),console.log(`â
Integration Tests Complete: ${this.results.length} tests run`),this.results})}getResults(){return this.results}getSummary(){const t=this.results.length,s=this.results.filter(n=>n.status==="passed").length,a=this.results.filter(n=>n.status==="failed").length,r=this.results.filter(n=>n.status==="warning").length,o=this.results.filter(n=>n.status==="failed"&&(n.category==="authentication"||n.category==="security")).length;return{total:t,passed:s,failed:a,warnings:r,criticalFailures:o,successRate:t>0?(s/t*100).toFixed(2):0,allTestsPassed:a===0,isProductionReady:a===0&&o===0}}}const R=new L,ae=()=>{var b;const[d,t]=P.useState([]),[s,a]=P.useState(!1),{user:r,role:o,isAuthenticated:n}=_(),m=()=>c(void 0,null,function*(){a(!0),t([]);try{const i=yield R.runAllIntegrationTests();t(i)}catch(i){console.error("Error running integration tests:",i)}finally{a(!1)}}),h=()=>{t([])},x=i=>{switch(i){case"passed":return e.jsx(H,{className:"w-4 h-4 text-green-600"});case"failed":return e.jsx(U,{className:"w-4 h-4 text-red-600"});case"warning":return e.jsx(S,{className:"w-4 h-4 text-yellow-600"});default:return e.jsx(S,{className:"w-4 h-4 text-gray-400"})}},N=i=>{const u={passed:"bg-green-100 text-green-800",failed:"bg-red-100 text-red-800",warning:"bg-yellow-100 text-yellow-800"};return e.jsx(C,{className:u[i],children:i.charAt(0).toUpperCase()+i.slice(1)})},E=i=>{const u={authentication:"bg-blue-100 text-blue-800",api:"bg-purple-100 text-purple-800",routing:"bg-green-100 text-green-800",dashboard:"bg-orange-100 text-orange-800",security:"bg-red-100 text-red-800"};return e.jsx(C,{className:u[i],children:i.toUpperCase()})},g=R.getSummary(),I=d.filter(i=>i.status==="failed"&&(i.category==="authentication"||i.category==="security"));return e.jsxs("div",{className:"max-w-6xl mx-auto p-6 space-y-6",children:[e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(j,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(M,{className:"w-6 h-6 text-blue-600"}),"Comprehensive Integration Test Suite"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(T,{onClick:m,disabled:s,className:"flex items-center gap-2",children:[e.jsx($,{className:"w-4 h-4"}),s?"Running Tests...":"Run Integration Tests"]}),e.jsxs(T,{variant:"outline",onClick:h,disabled:s,className:"flex items-center gap-2",children:[e.jsx(K,{className:"w-4 h-4"}),"Reset"]})]})]})}),e.jsxs(p,{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 bg-blue-50 rounded-lg",children:[e.jsx("h3",{className:"font-medium mb-2",children:"Current System Status"}),e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("div",{children:["Authentication: ",n?"â
Authenticated":"â Not Authenticated"]}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["User: ",r==null?void 0:r.email]}),e.jsxs("div",{children:["Role: ",o]}),e.jsxs("div",{children:["Location ID: ",((b=r==null?void 0:r.metadata)==null?void 0:b.primary_location_id)||"Not set"]})]})]})]}),d.length>0&&e.jsxs("div",{className:`p-4 rounded-lg ${g.isProductionReady?"bg-green-50":"bg-red-50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"font-medium",children:"Integration Test Summary"}),e.jsxs("div",{className:`text-lg font-bold ${g.isProductionReady?"text-green-600":"text-red-600"}`,children:[g.successRate,"% Success"]})]}
1),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4 text-sm",children:[e.jsxs("div",{children:["Total Tests: ",g.total]}),e.jsxs("div",{className:"text-green-600",children:["Passed: ",g.passed]}),e.jsxs("div",{className:"text-red-600",children:["Failed: ",g.failed]}),e.jsxs("div",{className:"text-yellow-600",children:["Warnings: ",g.warnings]}),e.jsxs("div",{className:"text-red-800",children:["Critical: ",g.criticalFailures]})]}),g.isProductionReady?e.jsx("div",{className:"mt-2 text-sm text-green-600",children:"ð System is production ready! All integration tests passed."}):e.jsx("div",{className:"mt-2 text-sm text-red-600",children:"â ï¸ System has integration issues that need to be resolved before production deployment."})]}),I.length>0&&e.jsxs("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:[e.jsxs("h3",{className:"font-medium text-red-800 mb-2",children:["Critical Integration Issues (",I.length,")"]}),e.jsx("div",{className:"space-y-1",children:I.map((i,u)=>e.jsxs("div",{className:"text-sm text-red-700",children:[e.jsx("strong",{children:i.name})," (",i.category,"): ",i.message]},u))})]})]})]}),d.length>0&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(y,{children:[e.jsx(w,{children:e.jsx(j,{className:"text-lg",children:"Authentication & Security"})}),e.jsx(p,{children:e.jsx("div",{className:"space-y-3",children:d.filter(i=>i.category==="authentication"||i.category==="security").map((i,u)=>e.jsxs("div",{className:"flex items-center justify-between p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[x(i.status),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:i.name}),i.status==="failed"&&e.jsx("div",{className:"text-xs text-red-600 mt-1",children:i.message})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-gray-500",children:[i.duration,"ms"]}),N(i.status)]})]},u))})})]}),e.jsxs(y,{children:[e.jsx(w,{children:e.jsx(j,{className:"text-lg",children:"API & Dashboard"})}),e.jsx(p,{children:e.jsx("div",{className:"space-y-3",children:d.filter(i=>i.category==="api"||i.category==="dashboard").map((i,u)=>e.jsxs("div",{className:"flex items-center justify-between p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[x(i.status),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:i.name}),i.status==="failed"&&e.jsx("div",{className:"text-xs text-red-600 mt-1",children:i.message})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-gray-500",children:[i.duration,"ms"]}),N(i.status)]})]},u))})})]})]}),d.length>0&&e.jsxs(y,{children:[e.jsx(w,{children:e.jsx(j,{children:"All Integration Test Results"})}),e.jsx(p,{children:e.jsx("div",{className:"space-y-3",children:d.map((i,u)=>e.jsxs("div",{className:"flex items-center justify-between p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[x(i.status),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:i.name}),e.jsx("div",{className:"text-sm text-gray-600",children:i.message})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[E(i.category),e.jsxs("span",{className:"text-xs text-gray-500",children:[i.duration,"ms"]}),N(i.status)]})]},u))})})]}),e.jsxs(y,{children:[e.jsx(w,{children:e.jsx(j,{children:"Integration Test Coverage"})}),e.jsx(p,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2 text-blue-800",children:"ð Authentication Integration"}),e.jsxs("ul",{className:"space-y-1 text-gray-600",children:[e.jsx("li",{children:"⢠Security fixes integration"}),e.jsx("li",{children:"⢠Session management validation"}),e.jsx("li",{children:"⢠Navigation security checks"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2 text-purple-800",children:"ð API Integration"}),e.jsxs("ul",{className:"space-y-1 text-gray-600",children:[e.jsx("li",{children:"⢠Enhanced BaseAPI usage"}),e.jsx("li",{children:"⢠Products API build fixes"}),e.jsx("li",{children:"⢠Analytics schema alignment"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2 text-green-800",children:"ð£ï¸ Routing Integration"}),e.jsxs("ul",{className:"space-y-1 text-gray-600",children:[e.jsx("li",{children:"⢠Component loading validation"}),e.jsx("li",{children:"⢠Protected route security"}),e.jsx("li",{children:"⢠Route accessibility checks"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2 text-orange-800",children:"ð Dashboard Integration"}),e.jsxs("ul",{className:"space-y-1 text-gray-600",children:[e.jsx("li",{children:"⢠Widget data loading"}),e.jsx("li",{children:"⢠KPI access control"}),e.jsx("li",{children:"⢠Metrics calculation"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2 text-red-800",children:"ð Security Integration"}),e.jsxs("ul",{className:"space-y-1 text-gray-600",children:[e.jsx("li",{children:"⢠Authentication bypass prevention"}),e.jsx("li",{children:"⢠Data access validation"}),e.jsx("li",{children:"⢠Permission enforcement"})]})]})]})})]})]})};export{ae as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.