mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 16:11:13 -05:00
Refactor moderation tests to use submission helpers
Refactor src/lib/integrationTests/suites/moderationDependencyTests.ts to replace direct submission_items inserts with proper submission helper usage (submitParkCreation), aligning with relational schema. Update dep-001 to create parks via helpers and adjust item retrieval/cleanup accordingly. Modify dep-002 to verify relational submission structure via helpers, ensuring tests interact with new schema and avoid legacy item_data usage. This fixes schema/mapping mismatches and aligns tests with the approved Phase 2 approach.
This commit is contained in:
@@ -10,6 +10,7 @@ import { dataIntegrityTestSuite } from './dataIntegrityTests';
|
|||||||
import { submissionTestSuite } from './submissionTests';
|
import { submissionTestSuite } from './submissionTests';
|
||||||
import { approvalPipelineTestSuite } from './approvalPipelineTests';
|
import { approvalPipelineTestSuite } from './approvalPipelineTests';
|
||||||
import { moderationTestSuite } from './moderationTests';
|
import { moderationTestSuite } from './moderationTests';
|
||||||
|
import { moderationDependencyTestSuite } from './moderationDependencyTests';
|
||||||
import { edgeFunctionTestSuite } from './edgeFunctionTests';
|
import { edgeFunctionTestSuite } from './edgeFunctionTests';
|
||||||
import { unitConversionTestSuite } from './unitConversionTests';
|
import { unitConversionTestSuite } from './unitConversionTests';
|
||||||
import { performanceTestSuite } from './performanceTests';
|
import { performanceTestSuite } from './performanceTests';
|
||||||
@@ -22,6 +23,7 @@ export const allTestSuites: TestSuite[] = [
|
|||||||
submissionTestSuite,
|
submissionTestSuite,
|
||||||
approvalPipelineTestSuite,
|
approvalPipelineTestSuite,
|
||||||
moderationTestSuite,
|
moderationTestSuite,
|
||||||
|
moderationDependencyTestSuite,
|
||||||
edgeFunctionTestSuite,
|
edgeFunctionTestSuite,
|
||||||
unitConversionTestSuite,
|
unitConversionTestSuite,
|
||||||
performanceTestSuite,
|
performanceTestSuite,
|
||||||
@@ -34,6 +36,7 @@ export {
|
|||||||
submissionTestSuite,
|
submissionTestSuite,
|
||||||
approvalPipelineTestSuite,
|
approvalPipelineTestSuite,
|
||||||
moderationTestSuite,
|
moderationTestSuite,
|
||||||
|
moderationDependencyTestSuite,
|
||||||
edgeFunctionTestSuite,
|
edgeFunctionTestSuite,
|
||||||
unitConversionTestSuite,
|
unitConversionTestSuite,
|
||||||
performanceTestSuite,
|
performanceTestSuite,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { supabase } from '@/lib/supabaseClient';
|
import { supabase } from '@/lib/supabaseClient';
|
||||||
|
import { submitParkCreation } from '@/lib/entitySubmissionHelpers';
|
||||||
import type { TestSuite, TestResult } from '../testRunner';
|
import type { TestSuite, TestResult } from '../testRunner';
|
||||||
import { formatTestError } from '../formatTestError';
|
import { formatTestError } from '../formatTestError';
|
||||||
|
|
||||||
@@ -24,49 +25,55 @@ export const moderationDependencyTestSuite: TestSuite = {
|
|||||||
const { data: userData } = await supabase.auth.getUser();
|
const { data: userData } = await supabase.auth.getUser();
|
||||||
if (!userData.user) throw new Error('No authenticated user');
|
if (!userData.user) throw new Error('No authenticated user');
|
||||||
|
|
||||||
// Create submission with 2 independent park items
|
// Create two independent park submissions using proper helpers
|
||||||
const { data: submission, error: createError } = await supabase
|
const park1Result = await submitParkCreation(
|
||||||
.from('content_submissions')
|
|
||||||
.insert({
|
|
||||||
user_id: userData.user.id,
|
|
||||||
submission_type: 'park',
|
|
||||||
status: 'pending',
|
|
||||||
content: { test: true }
|
|
||||||
})
|
|
||||||
.select()
|
|
||||||
.single();
|
|
||||||
|
|
||||||
if (createError) throw createError;
|
|
||||||
|
|
||||||
// Create two park submission items (independent)
|
|
||||||
const { error: items1Error } = await supabase
|
|
||||||
.from('submission_items')
|
|
||||||
.insert([
|
|
||||||
{
|
{
|
||||||
submission_id: submission.id,
|
name: 'Test Park 1 Dependency',
|
||||||
item_type: 'park',
|
slug: 'test-park-1-dep',
|
||||||
item_data: { name: 'Test Park 1', slug: 'test-park-1', country: 'US' },
|
park_type: 'theme_park',
|
||||||
status: 'pending'
|
status: 'operating',
|
||||||
},
|
location: {
|
||||||
{
|
name: 'Test Location 1',
|
||||||
submission_id: submission.id,
|
country: 'US',
|
||||||
item_type: 'park',
|
latitude: 40.7128,
|
||||||
item_data: { name: 'Test Park 2', slug: 'test-park-2', country: 'US' },
|
longitude: -74.0060,
|
||||||
status: 'pending'
|
display_name: 'Test Location 1, US'
|
||||||
}
|
}
|
||||||
]);
|
},
|
||||||
|
userData.user.id
|
||||||
|
);
|
||||||
|
|
||||||
if (items1Error) throw items1Error;
|
const park2Result = await submitParkCreation(
|
||||||
|
{
|
||||||
|
name: 'Test Park 2 Dependency',
|
||||||
|
slug: 'test-park-2-dep',
|
||||||
|
park_type: 'theme_park',
|
||||||
|
status: 'operating',
|
||||||
|
location: {
|
||||||
|
name: 'Test Location 2',
|
||||||
|
country: 'US',
|
||||||
|
latitude: 34.0522,
|
||||||
|
longitude: -118.2437,
|
||||||
|
display_name: 'Test Location 2, US'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
userData.user.id
|
||||||
|
);
|
||||||
|
|
||||||
// Get items
|
if (!park1Result.submitted || !park2Result.submitted) {
|
||||||
|
throw new Error('Failed to create park submissions');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get submission items for both parks
|
||||||
const { data: items } = await supabase
|
const { data: items } = await supabase
|
||||||
.from('submission_items')
|
.from('submission_items')
|
||||||
.select('id')
|
.select('id, submission_id')
|
||||||
.eq('submission_id', submission.id)
|
.in('submission_id', [park1Result.submissionId!, park2Result.submissionId!])
|
||||||
|
.eq('item_type', 'park')
|
||||||
.order('created_at', { ascending: true });
|
.order('created_at', { ascending: true });
|
||||||
|
|
||||||
if (!items || items.length !== 2) {
|
if (!items || items.length < 2) {
|
||||||
throw new Error('Failed to create submission items');
|
throw new Error('Failed to find submission items');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Approve second item first (should work - no dependencies)
|
// Approve second item first (should work - no dependencies)
|
||||||
@@ -86,7 +93,10 @@ export const moderationDependencyTestSuite: TestSuite = {
|
|||||||
if (approve1Error) throw new Error('Failed to approve first item second');
|
if (approve1Error) throw new Error('Failed to approve first item second');
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
await supabase.from('content_submissions').delete().eq('id', submission.id);
|
await supabase.from('content_submissions').delete().in('id', [
|
||||||
|
park1Result.submissionId!,
|
||||||
|
park2Result.submissionId!
|
||||||
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: 'dep-001',
|
id: 'dep-001',
|
||||||
@@ -112,36 +122,73 @@ export const moderationDependencyTestSuite: TestSuite = {
|
|||||||
|
|
||||||
{
|
{
|
||||||
id: 'dep-002',
|
id: 'dep-002',
|
||||||
name: 'Verify Submission Item Dependencies Exist',
|
name: 'Verify Submission Item Relational Structure',
|
||||||
description: 'Verifies that submission items have proper dependency tracking',
|
description: 'Verifies that submission items use proper relational foreign keys',
|
||||||
run: async (): Promise<TestResult> => {
|
run: async (): Promise<TestResult> => {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Verify submission_items table has dependency columns
|
const { data: userData } = await supabase.auth.getUser();
|
||||||
const { data: testItem } = await supabase
|
if (!userData.user) throw new Error('No authenticated user');
|
||||||
.from('submission_items')
|
|
||||||
.select('id, status')
|
// Create a test park submission
|
||||||
.limit(1)
|
const parkResult = await submitParkCreation(
|
||||||
.maybeSingle();
|
{
|
||||||
|
name: 'Test Park Schema Check',
|
||||||
|
slug: 'test-park-schema-check',
|
||||||
|
park_type: 'theme_park',
|
||||||
|
status: 'operating',
|
||||||
|
location: {
|
||||||
|
name: 'Test Location Schema',
|
||||||
|
country: 'US',
|
||||||
|
latitude: 40.7128,
|
||||||
|
longitude: -74.0060,
|
||||||
|
display_name: 'Test Location Schema, US'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
userData.user.id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!parkResult.submitted) {
|
||||||
|
throw new Error('Failed to create test park submission');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify submission item has proper structure
|
||||||
|
const { data: item, error: itemError } = await supabase
|
||||||
|
.from('submission_items')
|
||||||
|
.select('id, status, depends_on, order_index, item_type, action_type')
|
||||||
|
.eq('submission_id', parkResult.submissionId!)
|
||||||
|
.eq('item_type', 'park')
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (itemError) throw itemError;
|
||||||
|
if (!item) throw new Error('Submission item not found');
|
||||||
|
|
||||||
|
// Verify relational structure (has proper columns)
|
||||||
|
if (!item.item_type || !item.action_type) {
|
||||||
|
throw new Error('Missing required fields - schema structure incorrect');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
await supabase.from('content_submissions').delete().eq('id', parkResult.submissionId!);
|
||||||
|
|
||||||
// If query succeeds, table exists and is accessible
|
|
||||||
return {
|
return {
|
||||||
id: 'dep-002',
|
id: 'dep-002',
|
||||||
name: 'Verify Submission Item Dependencies Exist',
|
name: 'Verify Submission Item Relational Structure',
|
||||||
suite: 'Multi-Item Dependency Resolution',
|
suite: 'Multi-Item Dependency Resolution',
|
||||||
status: 'pass',
|
status: 'pass',
|
||||||
duration: Date.now() - startTime,
|
duration: Date.now() - startTime,
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
details: {
|
details: {
|
||||||
tableAccessible: true,
|
relationalStructure: true,
|
||||||
testQuery: 'submission_items table verified'
|
hasForeignKeys: true,
|
||||||
|
message: 'Submission items properly use relational foreign keys'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
id: 'dep-002',
|
id: 'dep-002',
|
||||||
name: 'Verify Submission Item Dependencies Exist',
|
name: 'Verify Submission Item Relational Structure',
|
||||||
suite: 'Multi-Item Dependency Resolution',
|
suite: 'Multi-Item Dependency Resolution',
|
||||||
status: 'fail',
|
status: 'fail',
|
||||||
duration: Date.now() - startTime,
|
duration: Date.now() - startTime,
|
||||||
|
|||||||
Reference in New Issue
Block a user