Skip to content

Commit

Permalink
End-to-end testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kennsippell committed Dec 10, 2024
1 parent bfa15c9 commit a00a2f9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docker-local-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ to build missing images";echo;
fi

echo;echo "Starting Docker Compose...";echo
CHT_USER_MANAGEMENT_IMAGE=cht-user-management:local CHT_USER_MANAGEMENT_WORKER_IMAGE=cht-user-management-worker:local docker compose up -d
CHT_USER_MANAGEMENT_IMAGE=cht-user-management:local CHT_USER_MANAGEMENT_WORKER_IMAGE=cht-user-management-worker:local docker compose up

echo;echo "Server is now running at http://127.0.0.1:$EXTERNAL_PORT/login";echo
68 changes: 36 additions & 32 deletions src/lib/manage-hierarchy.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ContactType } from '../config';
import SessionCache from '../services/session-cache';
import { ChtApi, RemotePlace } from './cht-api';
import RemotePlaceResolver from './remote-place-resolver';
import Place from '../services/place';
import _ from 'lodash';

import { JobParams, IQueue, getChtConfQueue } from './queues';
import Auth from './authentication';
import { ChtApi, RemotePlace } from './cht-api';
import { ChtConfJobData } from '../worker/cht-conf-worker';
import _ from 'lodash';
import { ContactType } from '../config';
import { JobParams, IQueue, getChtConfQueue } from './queues';
import Place from '../services/place';
import RemotePlaceResolver from './remote-place-resolver';
import SessionCache from '../services/session-cache';

export const HIERARCHY_ACTIONS = ['move', 'merge', 'delete'];
export type HierarchyAction = typeof HIERARCHY_ACTIONS[number];
Expand Down Expand Up @@ -47,7 +47,7 @@ async function getJobDetails(formData: any, contactType: ContactType, sessionCac
const sourceLineage = await resolve('source_', formData, contactType, sessionCache, chtApi);
const destinationLineage = hierarchyAction === 'delete' ? [] : await resolve('destination_', formData, contactType, sessionCache, chtApi);

const { sourceId, destinationId } = getSourceAndDestination();
const { sourceId, destinationId } = getSourceAndDestinationIds(hierarchyAction, sourceLineage, destinationLineage);
const jobData = getJobData(hierarchyAction, sourceId, destinationId, chtApi);
const jobName = getJobName(jobData.action, sourceLineage, destinationLineage);
const jobParam: JobParams = {
Expand All @@ -60,38 +60,42 @@ async function getJobDetails(formData: any, contactType: ContactType, sessionCac
destinationLineage,
jobParam
};
}

function getSourceAndDestination() {
const sourceId = sourceLineage[0]?.id;
if (!sourceId) {
throw Error('Unexpected error: Hierarchy operation failed due to missing source information');
}
function getSourceAndDestinationIds(
hierarchyAction: HierarchyAction,
sourceLineage: (RemotePlace | undefined)[],
destinationLineage: (RemotePlace | undefined)[]
) {
const sourceId = sourceLineage[0]?.id;
if (!sourceId) {
throw Error('Unexpected error: Hierarchy operation failed due to missing source information');
}

if (hierarchyAction === 'delete') {
return { sourceId, destinationId: '' };
}
if (hierarchyAction === 'delete') {
return { sourceId, destinationId: '' };
}

const destinationIndex = hierarchyAction === 'move' ? 1 : 0;
const destinationId = destinationLineage[destinationIndex]?.id;
if (!destinationId) {
throw Error('Unexpected error: Hierarchy operation due to missing destination information');
}
const destinationIndex = hierarchyAction === 'move' ? 1 : 0;
const destinationId = destinationLineage[destinationIndex]?.id;
if (!destinationId) {
throw Error('Unexpected error: Hierarchy operation due to missing destination information');
}


if (hierarchyAction === 'move') {
if (destinationId === sourceLineage[1]?.id) {
throw Error(`Place "${sourceLineage[0]?.name}" already has "${destinationLineage[1]?.name}" as parent`);
}
if (hierarchyAction === 'move') {
if (destinationId === sourceLineage[1]?.id) {
throw Error(`Place "${sourceLineage[0]?.name}" already has "${destinationLineage[1]?.name}" as parent`);
}
if (hierarchyAction === 'merge') {
if (destinationId === sourceId) {
throw Error(`Cannot merge "${destinationId}" with self`);
}
}

if (hierarchyAction === 'merge') {
if (destinationId === sourceId) {
throw Error(`Cannot merge "${destinationId}" with self`);
}

return { sourceId, destinationId };
}

return { sourceId, destinationId };
}

function getJobName(action: string, sourceLineage: (RemotePlace | undefined)[], destinationLineage: (RemotePlace | undefined)[]): string {
Expand Down

0 comments on commit a00a2f9

Please sign in to comment.