@@ -844,6 +844,7 @@ describe('placeOfEvent location hierarchy handling', () => {
844844 let grandParentLocation : Location
845845 let parentLocation : Location
846846 let childOffice : Location
847+ let modifiedEventConfig : EventConfig
847848 beforeEach ( async ( ) => {
848849 // Setup: Generate location IDs upfront
849850 const prng = createPrng ( 942 )
@@ -864,8 +865,7 @@ describe('placeOfEvent location hierarchy handling', () => {
864865 } ,
865866 defaultValue : {
866867 country : 'FAR' ,
867- addressType : AddressType . DOMESTIC ,
868- administrativeArea : parentLocationId
868+ addressType : AddressType . DOMESTIC
869869 } ,
870870 conditionals,
871871 configuration : {
@@ -884,7 +884,7 @@ describe('placeOfEvent location hierarchy handling', () => {
884884 }
885885 } )
886886
887- const modifiedEventConfig : EventConfig = {
887+ modifiedEventConfig = {
888888 ...tennisClubMembershipEvent ,
889889 declaration : {
890890 ...tennisClubMembershipEvent . declaration ,
@@ -897,7 +897,7 @@ describe('placeOfEvent location hierarchy handling', () => {
897897 fields : [
898898 ...page . fields . filter ( ( x ) => x . type !== FieldType . ADDRESS ) ,
899899 {
900- id : 'addressType ' ,
900+ id : 'selected.address.type ' ,
901901 type : FieldType . TEXT ,
902902 label : {
903903 id : 'addressType.label' ,
@@ -909,13 +909,17 @@ describe('placeOfEvent location hierarchy handling', () => {
909909 createAddressField ( 'home.address' , [
910910 {
911911 type : 'SHOW' ,
912- conditional : field ( 'addressType' ) . isEqualTo ( 'home.address' )
912+ conditional : field ( 'selected.address.type' ) . isEqualTo (
913+ 'home.address'
914+ )
913915 }
914916 ] ) ,
915917 createAddressField ( 'office.address' , [
916918 {
917919 type : 'SHOW' ,
918- conditional : field ( 'addressType' ) . isEqualTo ( 'office.address' )
920+ conditional : field ( 'selected.address.type' ) . isEqualTo (
921+ 'office.address'
922+ )
919923 }
920924 ] )
921925 ]
@@ -981,7 +985,7 @@ describe('placeOfEvent location hierarchy handling', () => {
981985 ActionType . DECLARE ,
982986 createPrng ( 100 )
983987 ) ,
984- addressType : 'home.address' ,
988+ 'selected.address.type' : 'home.address' ,
985989 'home.address' : {
986990 country : 'FAR' ,
987991 streetLevelDetails : { town : 'Gazipur' } ,
@@ -1081,7 +1085,7 @@ describe('placeOfEvent location hierarchy handling', () => {
10811085 generator . event . actions . register ( createdEvent . id , {
10821086 declaration : {
10831087 ...declarationWithoutHomeAddress ,
1084- addressType : 'office.address' ,
1088+ 'selected.address.type' : 'office.address' ,
10851089 'office.address' : {
10861090 country : 'FAR' ,
10871091 streetLevelDetails : { town : 'Dhaka' } ,
@@ -1226,4 +1230,164 @@ describe('placeOfEvent location hierarchy handling', () => {
12261230 } )
12271231 }
12281232 } )
1233+
1234+ test ( 'records are indexed with createdAtLocation for AddressType.INTERNATIONAL' , async ( ) => {
1235+ // Step 1: Create and declare events with international address
1236+
1237+ const declarationWithInternationalAddress = {
1238+ ...generateActionDeclarationInput (
1239+ modifiedEventConfig ,
1240+ ActionType . DECLARE ,
1241+ createPrng ( 100 )
1242+ ) ,
1243+ 'selected.address.type' : 'home.address' ,
1244+ 'home.address' : {
1245+ country : 'USA' ,
1246+ addressType : AddressType . INTERNATIONAL ,
1247+ streetLevelDetails : {
1248+ town : 'Oklahoma'
1249+ }
1250+ }
1251+ }
1252+
1253+ const event = await client . event . create (
1254+ generator . event . create ( { type : TENNIS_CLUB_MEMBERSHIP } )
1255+ )
1256+
1257+ await client . event . actions . declare . request (
1258+ generator . event . actions . declare ( event . id , {
1259+ declaration : declarationWithInternationalAddress ,
1260+ keepAssignment : true
1261+ } )
1262+ )
1263+
1264+ await client . event . actions . validate . request (
1265+ generator . event . actions . validate ( event . id , {
1266+ declaration : declarationWithInternationalAddress ,
1267+ keepAssignment : true
1268+ } )
1269+ )
1270+
1271+ // Step 2: Verify events are indexed correctly BEFORE reindexing
1272+ const initialSearchResponse = await esClient . search ( {
1273+ index : getEventIndexName ( TENNIS_CLUB_MEMBERSHIP ) ,
1274+ body : { query : { match_all : { } } }
1275+ } )
1276+
1277+ expect ( initialSearchResponse . hits . hits ) . toHaveLength ( 1 )
1278+
1279+ const expectedLocationHierarchy = {
1280+ type : TENNIS_CLUB_MEMBERSHIP ,
1281+ status : 'DECLARED' ,
1282+ createdAtLocation : [
1283+ grandParentLocation . id ,
1284+ parentLocation . id ,
1285+ childOffice . id
1286+ ] ,
1287+ updatedAtLocation : [
1288+ grandParentLocation . id ,
1289+ parentLocation . id ,
1290+ childOffice . id
1291+ ] ,
1292+ placeOfEvent : [ grandParentLocation . id , parentLocation . id , childOffice . id ] ,
1293+ legalStatuses : {
1294+ DECLARED : {
1295+ createdAtLocation : [
1296+ grandParentLocation . id ,
1297+ parentLocation . id ,
1298+ childOffice . id
1299+ ]
1300+ }
1301+ } ,
1302+ declaration : {
1303+ home____address : {
1304+ addressType : AddressType . INTERNATIONAL ,
1305+ country : 'USA' ,
1306+ streetLevelDetails : {
1307+ town : 'Oklahoma'
1308+ }
1309+ }
1310+ }
1311+ }
1312+
1313+ expect ( initialSearchResponse . hits . hits [ 0 ] . _source ) . toMatchObject (
1314+ expectedLocationHierarchy
1315+ )
1316+ } )
1317+
1318+ test ( 'records are indexed with createdAtLocation for no placeOfEvent config' , async ( ) => {
1319+ // Step 1: Create and declare events with international address
1320+ mswServer . use (
1321+ http . get ( `${ env . COUNTRY_CONFIG_URL } /events` , ( ) => {
1322+ return HttpResponse . json ( [
1323+ { ...modifiedEventConfig , placeOfEvent : undefined }
1324+ ] )
1325+ } )
1326+ )
1327+
1328+ const event = await client . event . create (
1329+ generator . event . create ( { type : TENNIS_CLUB_MEMBERSHIP } )
1330+ )
1331+
1332+ await client . event . actions . declare . request (
1333+ generator . event . actions . declare ( event . id , {
1334+ declaration : declarationWithHomeAddress ,
1335+ keepAssignment : true
1336+ } )
1337+ )
1338+
1339+ await client . event . actions . validate . request (
1340+ generator . event . actions . validate ( event . id , {
1341+ declaration : declarationWithHomeAddress ,
1342+ keepAssignment : true
1343+ } )
1344+ )
1345+
1346+ // Step 2: Verify events are indexed correctly BEFORE reindexing
1347+ const initialSearchResponse = await esClient . search ( {
1348+ index : getEventIndexName ( TENNIS_CLUB_MEMBERSHIP ) ,
1349+ body : { query : { match_all : { } } }
1350+ } )
1351+
1352+ expect ( initialSearchResponse . hits . hits ) . toHaveLength ( 1 )
1353+
1354+ const expectedLocationHierarchy = {
1355+ type : TENNIS_CLUB_MEMBERSHIP ,
1356+ status : 'DECLARED' ,
1357+ createdAtLocation : [
1358+ grandParentLocation . id ,
1359+ parentLocation . id ,
1360+ childOffice . id
1361+ ] ,
1362+ updatedAtLocation : [
1363+ grandParentLocation . id ,
1364+ parentLocation . id ,
1365+ childOffice . id
1366+ ] ,
1367+ placeOfEvent : [ grandParentLocation . id , parentLocation . id , childOffice . id ] ,
1368+ legalStatuses : {
1369+ DECLARED : {
1370+ createdAtLocation : [
1371+ grandParentLocation . id ,
1372+ parentLocation . id ,
1373+ childOffice . id
1374+ ]
1375+ }
1376+ } ,
1377+ declaration : {
1378+ home____address : {
1379+ addressType : 'DOMESTIC' ,
1380+ country : 'FAR' ,
1381+ streetLevelDetails : {
1382+ town : 'Gazipur'
1383+ } ,
1384+ administrativeArea : [ grandParentLocation . id , parentLocation . id ]
1385+ }
1386+ }
1387+ }
1388+
1389+ expect ( initialSearchResponse . hits . hits [ 0 ] . _source ) . toMatchObject (
1390+ expectedLocationHierarchy
1391+ )
1392+ } )
12291393} )
0 commit comments