add tests batch 20

This commit is contained in:
root
2026-06-09 01:03:53 -04:00
parent 95efb9652e
commit 6be4875c5e
1502 changed files with 13797 additions and 11313 deletions
@@ -13,12 +13,12 @@ class WhatsappInviteBundleService
$isPrimary = User::query()->whereKey($pickedId)->exists();
$primaryId = $pickedId;
if (! $isPrimary) {
if (!$isPrimary) {
$map = ParentModel::query()
->select('firstparent_id', 'id')
->where('id', $pickedId)
->first();
if (! $map || ! $map->firstparent_id) {
if (!$map || !$map->firstparent_id) {
return null;
}
$primaryId = (int) $map->firstparent_id;
@@ -28,7 +28,7 @@ class WhatsappInviteBundleService
->select('id', 'firstname', 'lastname', 'email')
->whereKey($primaryId)
->first();
if (! $primary) {
if (!$primary) {
return null;
}
@@ -50,7 +50,7 @@ class WhatsappInviteBundleService
$linksSet = [];
foreach ($sectionRows as $row) {
$cid = (int) ($row->class_section_id ?? 0);
if (! $cid) {
if (!$cid) {
continue;
}
$link = (string) ($linkBySection[$cid]['invite_link'] ?? '');
@@ -60,7 +60,7 @@ class WhatsappInviteBundleService
$sections[] = [
'class_section_id' => $cid,
'class_section_name' => (string) ($linkBySection[$cid]['class_section_name'] ?? ('Section '.$cid)),
'class_section_name' => (string) ($linkBySection[$cid]['class_section_name'] ?? ('Section ' . $cid)),
'invite_link' => $link,
];
$linksSet[$link] = true;
@@ -71,10 +71,10 @@ class WhatsappInviteBundleService
}
$emails = [];
if (! empty($primary->email)) {
if (!empty($primary->email)) {
$emails[$primary->email] = true;
}
if (! empty($secondary?->secondparent_email)) {
if (!empty($secondary?->secondparent_email)) {
$emails[$secondary->secondparent_email] = true;
}
if (empty($emails)) {
@@ -89,7 +89,7 @@ class WhatsappInviteBundleService
'email' => (string) ($primary->email ?? ''),
'source' => 'users',
],
'secondary_parents' => $secondary && ! empty($secondary->id) ? [[
'secondary_parents' => $secondary && !empty($secondary->id) ? [[
'id' => (int) $secondary->id,
'firstname' => (string) ($secondary->secondparent_firstname ?? ''),
'lastname' => (string) ($secondary->secondparent_lastname ?? ''),
@@ -186,15 +186,15 @@ class WhatsappInviteBundleService
$bundles = [];
foreach ($parentIds as $pid) {
$profile = $profiles[$pid] ?? null;
if (! $profile) {
if (!$profile) {
continue;
}
$emails = [];
if (! empty($profile['email'])) {
if (!empty($profile['email'])) {
$emails[$profile['email']] = true;
}
if (! empty($secondaryByPrimary[$pid]['email'])) {
if (!empty($secondaryByPrimary[$pid]['email'])) {
$emails[$secondaryByPrimary[$pid]['email']] = true;
}
if (empty($emails)) {
@@ -203,10 +203,10 @@ class WhatsappInviteBundleService
$bundles[] = [
'parent' => $profile,
'secondary_parents' => ! empty($secondaryByPrimary[$pid]['id']) ? [$secondaryByPrimary[$pid]] : [],
'secondary_parents' => !empty($secondaryByPrimary[$pid]['id']) ? [$secondaryByPrimary[$pid]] : [],
'sections' => [[
'class_section_id' => $classSectionId,
'class_section_name' => (string) ($linkBySection[$classSectionId]['class_section_name'] ?? ('Section '.$classSectionId)),
'class_section_name' => (string) ($linkBySection[$classSectionId]['class_section_name'] ?? ('Section ' . $classSectionId)),
'invite_link' => $link,
]],
'links' => [$link],
@@ -232,7 +232,7 @@ class WhatsappInviteBundleService
$bundles = [];
foreach ($sectionRows as $row) {
$cid = (int) ($row->class_section_id ?? 0);
if (! $cid) {
if (!$cid) {
continue;
}
@@ -255,7 +255,6 @@ class WhatsappInviteBundleService
$out[$e] = true;
}
}
return array_keys($out);
};
@@ -265,7 +264,6 @@ class WhatsappInviteBundleService
$k = is_array($v) ? md5(json_encode($v)) : (string) $v;
$map[$k] = $v;
}
return array_values($map);
};
@@ -275,10 +273,10 @@ class WhatsappInviteBundleService
if (is_array($row)) {
$id = $row['class_section_id'] ?? null;
$name = $row['class_section_name'] ?? null;
$key = $id !== null ? ('id:'.(int) $id) : ('name:'.(string) $name);
$key = $id !== null ? ('id:' . (int) $id) : ('name:' . (string) $name);
$byKey[$key] = $row;
} else {
$byKey['name:'.(string) $row] = $row;
$byKey['name:' . (string) $row] = $row;
}
};
@@ -297,11 +295,11 @@ class WhatsappInviteBundleService
$add = static function (&$index, $item) {
if (is_array($item)) {
$key = isset($item['class_section_id'])
? 'id:'.(int) $item['class_section_id']
: ('url:'.(string) ($item['invite_link'] ?? json_encode($item)));
? 'id:' . (int) $item['class_section_id']
: ('url:' . (string) ($item['invite_link'] ?? json_encode($item)));
$index[$key] = $item;
} else {
$index['url:'.(string) $item] = $item;
$index['url:' . (string) $item] = $item;
}
};
@@ -320,9 +318,9 @@ class WhatsappInviteBundleService
$parent = $bundle['parent'] ?? [];
$pid = (int) ($parent['id'] ?? 0);
$primaryEmails = $normalizeEmails((array) ($bundle['emails'] ?? []));
$groupKey = $pid > 0 ? ('pid:'.$pid) : ('mail:'.implode(',', $primaryEmails));
$groupKey = $pid > 0 ? ('pid:' . $pid) : ('mail:' . implode(',', $primaryEmails));
if (! isset($grouped[$groupKey])) {
if (!isset($grouped[$groupKey])) {
$grouped[$groupKey] = [
'parent' => $parent,
'emails' => $primaryEmails,
@@ -332,11 +330,10 @@ class WhatsappInviteBundleService
'items' => (array) ($bundle['items'] ?? []),
'secondary_parents' => (array) ($bundle['secondary_parents'] ?? []),
];
continue;
}
$grouped[$groupKey]['parent'] = ! empty($parent) ? $parent : $grouped[$groupKey]['parent'];
$grouped[$groupKey]['parent'] = !empty($parent) ? $parent : $grouped[$groupKey]['parent'];
$grouped[$groupKey]['emails'] = $normalizeEmails(array_merge($grouped[$groupKey]['emails'], $primaryEmails));
$grouped[$groupKey]['sections'] = $mergeSections($grouped[$groupKey]['sections'], (array) ($bundle['sections'] ?? []));
$grouped[$groupKey]['links'] = $mergeLinks($grouped[$groupKey]['links'], (array) ($bundle['links'] ?? []));