Eliminate code duplication in test setup and service data fetching#9
Merged
CropWatchDevelopment merged 5 commits intoJan 20, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: CropWatchDevelopment <111664979+CropWatchDevelopment@users.noreply.github.com>
Co-authored-by: CropWatchDevelopment <111664979+CropWatchDevelopment@users.noreply.github.com>
Co-authored-by: CropWatchDevelopment <111664979+CropWatchDevelopment@users.noreply.github.com>
Co-authored-by: CropWatchDevelopment <111664979+CropWatchDevelopment@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor similar code in AirController and AirService tests
Eliminate code duplication in test setup and service data fetching
Jan 20, 2026
CropWatchDevelopment
approved these changes
Jan 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Qlty identified ~200 lines of duplicated code across test files and service classes in the air, water, soil, and traffic modules.
Changes
Test Setup Consolidation
createTestingModuleWithCommonProviders()insrc/common/test-helpers.tsService Layer Abstraction
BaseDataService<T>abstract class insrc/common/base-data.service.tsfindOne()implementation: Supabase query, timezone validation/formatting, error handlingBefore:
After:
Pattern applies identically to water, soil, and traffic services.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
scarf.sh/usr/local/bin/node node ./report.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>Qlty: Found 29 lines of similar code in 4 locations (mass = 159)</issue_title>
<issue_description>Issue on Qlty
Found 27 lines of similar code in 4 locations (mass = 83)
src/air/air.controller.spec.ts
import
{ Test, TestingModule }
from
'@nestjs/testing'
;
import
{ AirController }
from
'./air.controller'
;
import
{ AirService }
from
'./air.service'
;
import
{ SupabaseService }
from
'../supabase/supabase.service'
;
import
{ TimezoneFormatterService }
from
'../common/timezone-formatter.service'
;
describe(
'AirController'
,
() =>
{
let
controller: AirController;
beforeEach(
async
() => {
Found 25 lines of similar code in 4 locations (mass = 79)
src/air/air.service.spec.ts
import
{ Test, TestingModule }
from
'@nestjs/testing'
;
import
{ AirService }
from
'./air.service'
;
import
{ SupabaseService }
from
'../supabase/supabase.service'
;
import
{ TimezoneFormatterService }
from
'../common/timezone-formatter.service'
;
describe(
'AirService'
,
() =>
{
let
service: AirService;
beforeEach(
async
() => {
const
module
: TestingModule =
await
Test.createTestingModule({
Found 29 lines of similar code in 4 locations (mass = 159)
src/air/air.service.ts
string
,
startDate
:
Date
,
endDate
:
Date
,
timezone?:
string
,
):
Promise
<TableRow<
'cw_air_data'
const
normalizedTimeZone = timezone?.trim() ||
null
;
if
(normalizedTimeZone) {
this
.timezoneFormatter.assertValidTimeZone(normalizedTimeZone);
}
Found 19 lines of similar code in 2 locations (mass = 71)
src/power/power.service.spec.ts
import
{ Test, TestingModule }
from
'@nestjs/testing'
;
import
{ PowerService }
from
'./power.service'
;
describe(
'PowerService'
,
() =>
{
let
service: PowerService;
beforeEach(
async
() => {
const
module
: TestingModule =
await
Test.createTestingModule({
providers
: [PowerService],
}).compile();
Found 19 lines of similar code in 2 locations (mass = 71)
src/realtime/realtime.service.spec.ts
import
{ Test, TestingModule }
from
'@nestjs/testing'
;
import
{ RealtimeService }
from
'./realtime.service'
;
describe(
'RealtimeService'
,
() =>
{
let
service: RealtimeService;
beforeEach(
async
() => {
const
module
: TestingModule =
await
Test.createTestingModule({
providers
: [RealtimeService],
}).compile();
Found 27 lines of similar code in 4 locations (mass = 83)
src/soil/soil.controller.spec.ts
import
{ Test, TestingModule }
from
'@nestjs/testing'
;
import
{ SoilController }
from
'./soil.controller'
;
import
{ SoilService }
from
'./soil.service'
;
import
{ SupabaseService }
from
'../supabase/supabase.service'
;
import
{ TimezoneFormatterService }
from
'../common/timezone-formatter.service'
;
describe(
'SoilController'
,
() =>
{
let
controller: SoilController;
beforeEach(
async
() => {
Found 90 lines of similar code in 3 locations (mass = 423)
src/soil/soil.controller.ts
import
{ BadRequestException, Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards }
from
'@nestjs/common'
;
import
{ SoilService }
from
'./soil.service'
;
import
{ SoilDataDto }
from
'./dto/soil-data.dto'
;
import
type
{ CreateSoilDto }
from
'./dto/create-soil.dto'
;
import
type
{ UpdateSoilDto }
from
'./dto/update-soil.dto'
;
import
{ JwtAuthGuard }
from
'../auth/guards/jwt.auth.guard'
;
import
{ ApiBadRequestResponse, ApiBearerAuth, ApiInternalServerErrorResponse, ApiOkResponse, ApiParam, ApiQuery, ApiSecurity, ApiUnauthorizedResponse }
from
'@nestjs/swagger'
;
import
{ ErrorResponseDto }
from
'../common/dto/error-response.dto'
;
@controller
(
'soil'
)
Found 25 lines of similar code in 4 locations (mass = 79)
src/soil/soil.service.spec.ts
import
{ Test, TestingModule }
from
'@nestjs/testing'
;
import
{ SoilService }
from
'./soil.service'
;
import
{ SupabaseService }
from
'../supabase/supabase.service'
;
import
{ TimezoneFormatterService...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.