Skip to content

Adds TestGroup property to TestItem for categorization and filtering#1162

Open
jSylvestre wants to merge 5 commits into
masterfrom
JCS/NewTestItemField
Open

Adds TestGroup property to TestItem for categorization and filtering#1162
jSylvestre wants to merge 5 commits into
masterfrom
JCS/NewTestItemField

Conversation

@jSylvestre

@jSylvestre jSylvestre commented May 7, 2026

Copy link
Copy Markdown
Member

This introduces a new TestGroup field in the TestItem domain object and database column. It allows test items to be associated with predefined groups (e.g., AnLab, SIF) and facilitates filtering available tests for clients. issue #1161

Summary by CodeRabbit

  • New Features
    • Test items can now be organized into one or more groups for improved categorization and management.
    • Four test group categories are available for classification: AnLab, SIF, ICPMS, CDFA.

This introduces a new TestGroup field in the TestItem domain object and database column. It allows test items to be associated with predefined groups (e.g., AnLab, SIF) and facilitates filtering available tests for clients.
issue #1161
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Rate limit exceeded

@jSylvestre has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 42 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aedd68a9-cd6e-4c69-9fcb-ee0d0e71ef9c

📥 Commits

Reviewing files that changed from the base of the PR and between 61a0df2 and b4f41ae.

📒 Files selected for processing (6)
  • Anlab.Mvc/Controllers/TestItemsController.cs
  • Anlab.Mvc/Views/TestItems/Create.cshtml
  • Anlab.Mvc/Views/TestItems/Edit.cshtml
  • Anlab.Mvc/Views/TestItems/Index.cshtml
  • Anlab.Mvc/Views/TestItems/_TestItemsDetails.cshtml
  • Anlab.Mvc/Views/TestItems/_TestItemsForm.cshtml
📝 Walkthrough

Walkthrough

Adds a new TestGroup string property and a NotMapped TestGroups array with pipe-delimited mapping to the TestItem domain model, introduces a TestGroups constants class, persists TestGroup as NVARCHAR(64) NOT NULL in dbo.TestItems, applies DDL formatting/constraint updates across several tables and a view, and updates tests to expect the new fields.

Changes

TestItem Group Addition

Layer / File(s) Summary
Domain Model
Anlab.Core/Domain/TestItem.cs
TestItem adds public string TestGroup { get; set; } = string.Empty; and [NotMapped] public string[] TestGroups which serializes/deserializes on `
Database — TestItems
Anlab.Sql/dbo/Tables/TestItems.sql
dbo.TestItems adds TestGroup NVARCHAR(64) NOT NULL DEFAULT('') to persist the domain property.
Database — Other Tables
Anlab.Sql/dbo/Tables/Orders.sql, Anlab.Sql/dbo/Tables/MailMessages.sql, Anlab.Sql/dbo/Tables/History.sql
Formatting and DDL adjustments: removed some inline foreign key constraints, added FailureCount INT NOT NULL DEFAULT 0 to MailMessages, and normalized column/default declarations.
Views
Anlab.Sql/dbo/Views/HistoricalSalesView.sql
View definition unchanged; added extended properties (MS_DiagramPaneCount, MS_DiagramPane1) for SSMS diagram metadata.
Tests
Test/TestsDatabase/TestItemTests.cs, Test/TestsModel/TestItemModelTest.cs
Updated expected field lists to include RequestOrder, TestGroup, and TestGroups in relevant assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A pipe and a string, now snug in the file,
Four named groups in a neat little pile,
DB gets a column, tests nod and agree,
Constants stand ready — quick, hop with me!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a TestGroup property to TestItem for categorization and filtering purposes, which aligns with the PR objectives and all file modifications.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch JCS/NewTestItemField

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
Anlab.Sql/dbo/Tables/TestItems.sql (1)

13-13: ⚡ Quick win

Constrain TestGroup values to the supported set.

Filtering logic depends on known groups, but the column currently accepts any string. Add a CHECK constraint to prevent drift and invalid data.

Suggested constraint
-    [TestGroup] NVARCHAR(64) NOT NULL, 
+    [TestGroup] NVARCHAR(64) NOT NULL,
+    CONSTRAINT [CK_TestItems_TestGroup] CHECK ([TestGroup] IN ('AnLab', 'SIF', 'ICPMS', 'CDFA')),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Anlab.Sql/dbo/Tables/TestItems.sql` at line 13, The TestItems table's
[TestGroup] NVARCHAR(64) currently accepts any string; add a CHECK constraint
(e.g., name it CK_TestItems_TestGroup) on the [TestGroup] column to only allow
the supported set of group values used by filtering logic (replace the
placeholder list with the actual allowed values), and deploy the constraint
alongside the table definition so invalid values are rejected at insert/update
time.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Anlab.Core/Domain/TestItem.cs`:
- Around line 34-35: The TestItem domain model's TestGroup property lacks the
[Required] attribute while the database marks that column as non-nullable, so
add the [Required] attribute to the TestGroup property in the TestItem class
(public string TestGroup { get; set; } = string.Empty;) to enforce validation
earlier; also ensure the System.ComponentModel.DataAnnotations namespace is
imported if not already.
- Around line 37-41: The TestGroups computed property is missing the [NotMapped]
attribute and EF Core will try to map it; add the [NotMapped] attribute above
the TestGroups property (the string[] TestGroups getter/setter that wraps
TestGroup and uses Split/Join) to match the Categories pattern so EF Core
ignores this computed array property during model building.

In `@Anlab.Sql/dbo/Tables/TestItems.sql`:
- Line 13: The new NOT NULL constraint on the TestItems.TestGroup column will
fail on populated DBs; add a safe rollout migration that (1) alters TestItems to
add TestGroup as NULL or with a temporary DEFAULT, (2) backfills existing rows
with a valid value (e.g. empty string or a sentinel) via an UPDATE, and then (3)
alter the column to NOT NULL and remove any temporary default; reference the
TestItems table and TestGroup column when implementing the migration and ensure
the backfill value matches application expectations.

---

Nitpick comments:
In `@Anlab.Sql/dbo/Tables/TestItems.sql`:
- Line 13: The TestItems table's [TestGroup] NVARCHAR(64) currently accepts any
string; add a CHECK constraint (e.g., name it CK_TestItems_TestGroup) on the
[TestGroup] column to only allow the supported set of group values used by
filtering logic (replace the placeholder list with the actual allowed values),
and deploy the constraint alongside the table definition so invalid values are
rejected at insert/update time.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 424bbda7-ac19-4eb9-8ba1-085ff4664fae

📥 Commits

Reviewing files that changed from the base of the PR and between 39ca59b and eda7e40.

📒 Files selected for processing (2)
  • Anlab.Core/Domain/TestItem.cs
  • Anlab.Sql/dbo/Tables/TestItems.sql

Comment on lines +34 to +35
[StringLength(64)]
public string TestGroup { get; set; } = string.Empty;

@coderabbitai coderabbitai Bot May 7, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Align domain validation with DB requiredness for TestGroup.

TestGroup is required in SQL, but the model doesn’t declare [Required]. Add it to fail early in validation instead of at persistence time.

Proposed fix
+        [Required]
         [StringLength(64)]
         public string TestGroup { get; set; } = string.Empty;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Anlab.Core/Domain/TestItem.cs` around lines 34 - 35, The TestItem domain
model's TestGroup property lacks the [Required] attribute while the database
marks that column as non-nullable, so add the [Required] attribute to the
TestGroup property in the TestItem class (public string TestGroup { get; set; }
= string.Empty;) to enforce validation earlier; also ensure the
System.ComponentModel.DataAnnotations namespace is imported if not already.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It defaults to an empty string, so isn't needed

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jSylvestre, that's a fair point — and actually a stronger reason than just nullability. Since [Required] rejects empty strings by default in .NET validation, adding it would break the intended behavior where an empty TestGroup is a valid state (matching the DB's DEFAULT('')). Acknowledging the flag was mistaken here.


✏️ Learnings added
Learnt from: jSylvestre
Repo: ucdavis/Anlab PR: 1162
File: Anlab.Core/Domain/TestItem.cs:34-35
Timestamp: 2026-05-07T17:20:34.929Z
Learning: In `Anlab.Core/Domain/TestItem.cs`, the `TestGroup` property on `TestItem` intentionally defaults to `string.Empty` and an empty string is a valid/allowed value (the SQL column is `NVARCHAR(64) NOT NULL DEFAULT('')`). Do not suggest adding `[Required]` to this property, as `[Required]` rejects empty strings by default in .NET and would break the intended behavior.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment thread Anlab.Core/Domain/TestItem.cs
Comment thread Anlab.Sql/dbo/Tables/TestItems.sql Outdated
jSylvestre added 3 commits May 7, 2026 08:34
This column facilitates categorization and filtering of test items, allowing them to be grouped (e.g., AnLab, SIF). This supports client-facing filtering of available tests.
issue #1161
The `TestGroups` property is a derived property from `TestGroup` and should
not be persisted to the database. Marking it with `[NotMapped]` prevents
Entity Framework Core from attempting to create a corresponding database
column for this computed property. Tests are updated to validate this
attribute and the overall configuration for both `TestGroup` and `TestGroups`.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
Anlab.Sql/dbo/Tables/MailMessages.sql (1)

6-15: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

MailMessages.OrderId lacks foreign key constraint.

OrderId (Line 6) is a nullable INT column with a dedicated NONCLUSTERED index (Lines 26-27), yet has no foreign key constraint to dbo.Orders(Id). This permits dangling references and violates referential integrity.

Proposed fix
     CONSTRAINT [PK_MailMessages] PRIMARY KEY CLUSTERED ([Id] ASC),
-    CONSTRAINT [FK_MailMessages_AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[AspNetUsers] ([Id])
+    CONSTRAINT [FK_MailMessages_AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[AspNetUsers] ([Id]),
+    CONSTRAINT [FK_MailMessages_Orders_OrderId] FOREIGN KEY ([OrderId]) REFERENCES [dbo].[Orders] ([Id])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Anlab.Sql/dbo/Tables/MailMessages.sql` around lines 6 - 15,
MailMessages.OrderId is missing a foreign-key constraint; add a FK from
MailMessages.OrderId to dbo.Orders(Id) by adding a constraint such as CONSTRAINT
[FK_MailMessages_Orders_OrderId] FOREIGN KEY ([OrderId]) REFERENCES
[dbo].[Orders] ([Id]) (optionally with an ON DELETE/UPDATE action you want) to
the CREATE TABLE for MailMessages (near CONSTRAINT [PK_MailMessages] and the
existing FK to AspNetUsers) or implement as an ALTER TABLE ... ADD CONSTRAINT if
changing the existing table.
Anlab.Sql/dbo/Tables/History.sql (1)

3-12: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Restore the History.OrderId foreign key constraint.

Line 3 defines OrderId INT NOT NULL, but line 11 only defines the primary key constraint; there is no foreign key to dbo.Orders(Id). This allows orphaned history records and weakens data integrity.

Proposed fix
 CREATE TABLE [dbo].[History] (
     [Id]             INT            IDENTITY (1, 1) NOT NULL,
     [OrderId]        INT            NOT NULL,
@@
-    CONSTRAINT [PK_History] PRIMARY KEY CLUSTERED ([Id] ASC)
+    CONSTRAINT [PK_History] PRIMARY KEY CLUSTERED ([Id] ASC),
+    CONSTRAINT [FK_History_Orders] FOREIGN KEY ([OrderId]) REFERENCES [dbo].[Orders] ([Id])
 );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Anlab.Sql/dbo/Tables/History.sql` around lines 3 - 12, The table definition
for History is missing a foreign key from History.OrderId to dbo.Orders(Id),
allowing orphaned rows; add a FOREIGN KEY constraint (e.g., CONSTRAINT
FK_History_OrderId FOREIGN KEY ([OrderId]) REFERENCES dbo.Orders([Id]) ) to the
History table definition (alongside or after CONSTRAINT [PK_History]) so
History.OrderId enforces referential integrity and choose the appropriate ON
DELETE/ON UPDATE behavior for your domain.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Anlab.Sql/dbo/Tables/Orders.sql`:
- Line 21: The Orders table's IsDeleted column is declared as BIT NOT NULL
without a default which breaks inserts that don't supply it; update the Orders
table schema so IsDeleted has a DB-level default of 0 (e.g., add a DEFAULT 0
constraint on the IsDeleted column) to preserve backward-compatible inserts and
consider adding a migration/ALTER TABLE to apply the default for existing
databases; keep the column name IsDeleted and the table name Orders when
locating the change.
- Line 4: The schema sync removed foreign key constraints and a default value
causing data-integrity and INSERT issues; restore the FK constraints linking
Orders.CreatorId to the Users (or appropriate principal) table and
Orders.ApprovedPaymentTransaction_Id to the PaymentTransactions (or appropriate
principal) table by adding back the corresponding ALTER TABLE ... ADD CONSTRAINT
... FOREIGN KEY declarations (use the original constraint names if known), and
restore the DEFAULT ((0)) for the Orders.IsDeleted column so inserts that omit
IsDeleted work; update the Orders table DDL around the columns
ApprovedPaymentTransaction_Id, CreatorId and IsDeleted and ensure the related
indexes on those columns are present (recreate any dropped indexes referenced in
the diff) so the soft-delete and FK-dependent views and logic continue to work.

---

Outside diff comments:
In `@Anlab.Sql/dbo/Tables/History.sql`:
- Around line 3-12: The table definition for History is missing a foreign key
from History.OrderId to dbo.Orders(Id), allowing orphaned rows; add a FOREIGN
KEY constraint (e.g., CONSTRAINT FK_History_OrderId FOREIGN KEY ([OrderId])
REFERENCES dbo.Orders([Id]) ) to the History table definition (alongside or
after CONSTRAINT [PK_History]) so History.OrderId enforces referential integrity
and choose the appropriate ON DELETE/ON UPDATE behavior for your domain.

In `@Anlab.Sql/dbo/Tables/MailMessages.sql`:
- Around line 6-15: MailMessages.OrderId is missing a foreign-key constraint;
add a FK from MailMessages.OrderId to dbo.Orders(Id) by adding a constraint such
as CONSTRAINT [FK_MailMessages_Orders_OrderId] FOREIGN KEY ([OrderId])
REFERENCES [dbo].[Orders] ([Id]) (optionally with an ON DELETE/UPDATE action you
want) to the CREATE TABLE for MailMessages (near CONSTRAINT [PK_MailMessages]
and the existing FK to AspNetUsers) or implement as an ALTER TABLE ... ADD
CONSTRAINT if changing the existing table.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 89808e46-d83f-44c8-9762-83004372b508

📥 Commits

Reviewing files that changed from the base of the PR and between eda7e40 and 61a0df2.

📒 Files selected for processing (8)
  • Anlab.Core/Domain/TestItem.cs
  • Anlab.Sql/dbo/Tables/History.sql
  • Anlab.Sql/dbo/Tables/MailMessages.sql
  • Anlab.Sql/dbo/Tables/Orders.sql
  • Anlab.Sql/dbo/Tables/TestItems.sql
  • Anlab.Sql/dbo/Views/HistoricalSalesView.sql
  • Test/TestsDatabase/TestItemTests.cs
  • Test/TestsModel/TestItemModelTest.cs
✅ Files skipped from review due to trivial changes (2)
  • Test/TestsDatabase/TestItemTests.cs
  • Anlab.Sql/dbo/Views/HistoricalSalesView.sql
🚧 Files skipped from review as they are similar to previous changes (2)
  • Anlab.Sql/dbo/Tables/TestItems.sql
  • Anlab.Core/Domain/TestItem.cs

Comment thread Anlab.Sql/dbo/Tables/Orders.sql
Comment thread Anlab.Sql/dbo/Tables/Orders.sql
Integrates the TestGroup property into the TestItem create, edit, details, and index views. This allows for multi-selection of test groups when creating or editing a test item, and provides filtering capabilities in the list view, similar to existing category functionality.

This work completes the UI aspect of issue #1161.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant