diff --git a/.github/workflows/partial-backend.yaml b/.github/workflows/partial-backend.yaml index 1bb0dce..3e23d59 100644 --- a/.github/workflows/partial-backend.yaml +++ b/.github/workflows/partial-backend.yaml @@ -16,6 +16,8 @@ jobs: - name: Install Task uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: golangci-lint uses: golangci/golangci-lint-action@v3 diff --git a/.github/workflows/partial-frontend.yaml b/.github/workflows/partial-frontend.yaml index fcbfcbd..c83a1bd 100644 --- a/.github/workflows/partial-frontend.yaml +++ b/.github/workflows/partial-frontend.yaml @@ -14,6 +14,8 @@ jobs: - name: Install Task uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Set up Go uses: actions/setup-go@v2 diff --git a/backend/internal/core/services/service_items_csv_test.go b/backend/internal/core/services/service_items_csv_test.go index 8c453e8..b5b488c 100644 --- a/backend/internal/core/services/service_items_csv_test.go +++ b/backend/internal/core/services/service_items_csv_test.go @@ -3,18 +3,22 @@ package services import ( "bytes" "encoding/csv" + "fmt" "reflect" "testing" + "time" + + "github.com/stretchr/testify/assert" ) const CSV_DATA = ` Import Ref,Location,Labels,Quantity,Name,Description,Insured,Serial Number,Mode Number,Manufacturer,Notes,Purchase From,Purchased Price,Purchased Time,Lifetime Warranty,Warranty Expires,Warranty Details,Sold To,Sold Price,Sold Time,Sold Notes -A,Garage,IOT;Home Assistant; Z-Wave,1,Zooz Universal Relay ZEN17,"Zooz 700 Series Z-Wave Universal Relay ZEN17 for Awnings, Garage Doors, Sprinklers, and More | 2 NO-C-NC Relays (20A, 10A) | Signal Repeater | Hub Required (Compatible with SmartThings and Hubitat)",,,ZEN17,Zooz,,Amazon,39.95,10/13/2021,,,,,,, -B,Living Room,IOT;Home Assistant; Z-Wave,1,Zooz Motion Sensor,"Zooz Z-Wave Plus S2 Motion Sensor ZSE18 with Magnetic Mount, Works with Vera and SmartThings",,,ZSE18,Zooz,,Amazon,29.95,10/15/2021,,,,,,, -C,Office,IOT;Home Assistant; Z-Wave,1,Zooz 110v Power Switch,"Zooz Z-Wave Plus Power Switch ZEN15 for 110V AC Units, Sump Pumps, Humidifiers, and More",,,ZEN15,Zooz,,Amazon,39.95,10/13/2021,,,,,,, -D,Downstairs,IOT;Home Assistant; Z-Wave,1,Ecolink Z-Wave PIR Motion Sensor,"Ecolink Z-Wave PIR Motion Detector Pet Immune, White (PIRZWAVE2.5-ECO)",,,PIRZWAVE2.5-ECO,Ecolink,,Amazon,35.58,10/21/2020,,,,,,, -E,Entry,IOT;Home Assistant; Z-Wave,1,Yale Security Touchscreen Deadbolt,"Yale Security YRD226-ZW2-619 YRD226ZW2619 Touchscreen Deadbolt, Satin Nickel",,,YRD226ZW2619,Yale,,Amazon,120.39,10/14/2020,,,,,,, -F,Kitchen,IOT;Home Assistant; Z-Wave,1,Smart Rocker Light Dimmer,"UltraPro Z-Wave Smart Rocker Light Dimmer with QuickFit and SimpleWire, 3-Way Ready, Compatible with Alexa, Google Assistant, ZWave Hub Required, Repeater/Range Extender, White Paddle Only, 39351",,,39351,Honeywell,,Amazon,65.98,09/30/0202,,,,,,,` +A,Garage,IOT;Home Assistant; Z-Wave,1,Zooz Universal Relay ZEN17,Description 1,TRUE,,ZEN17,Zooz,,Amazon,39.95,10/13/2021,,10/13/2021,,,,10/13/2021, +B,Living Room,IOT;Home Assistant; Z-Wave,1,Zooz Motion Sensor,Description 2,FALSE,,ZSE18,Zooz,,Amazon,29.95,10/15/2021,,10/15/2021,,,,10/15/2021, +C,Office,IOT;Home Assistant; Z-Wave,1,Zooz 110v Power Switch,Description 3,TRUE,,ZEN15,Zooz,,Amazon,39.95,10/13/2021,,10/13/2021,,,,10/13/2021, +D,Downstairs,IOT;Home Assistant; Z-Wave,1,Ecolink Z-Wave PIR Motion Sensor,Description 4,FALSE,,PIRZWAVE2.5-ECO,Ecolink,,Amazon,35.58,10/21/2020,,10/21/2020,,,,10/21/2020, +E,Entry,IOT;Home Assistant; Z-Wave,1,Yale Security Touchscreen Deadbolt,Description 5,TRUE,,YRD226ZW2619,Yale,,Amazon,120.39,10/14/2020,,10/14/2020,,,,10/14/2020, +F,Kitchen,IOT;Home Assistant; Z-Wave,1,Smart Rocker Light Dimmer,Description 6,FALSE,,39351,Honeywell,,Amazon,65.98,09/30/2020,,09/30/2020,,,,09/30/2020,` func loadcsv() [][]string { reader := csv.NewReader(bytes.NewBuffer([]byte(CSV_DATA))) @@ -27,6 +31,33 @@ func loadcsv() [][]string { return records } +func Test_CorrectDateParsing(t *testing.T) { + t.Parallel() + + expected := []time.Time{ + time.Date(2021, 10, 13, 0, 0, 0, 0, time.UTC), + time.Date(2021, 10, 15, 0, 0, 0, 0, time.UTC), + time.Date(2021, 10, 13, 0, 0, 0, 0, time.UTC), + time.Date(2020, 10, 21, 0, 0, 0, 0, time.UTC), + time.Date(2020, 10, 14, 0, 0, 0, 0, time.UTC), + time.Date(2020, 9, 30, 0, 0, 0, 0, time.UTC), + } + + records := loadcsv() + + for i, record := range records { + if i == 0 { + continue + } + entity := newCsvRow(record) + expected := expected[i-1] + + assert.Equal(t, expected, entity.Item.PurchaseTime, fmt.Sprintf("Failed on row %d", i)) + assert.Equal(t, expected, entity.Item.WarrantyExpires, fmt.Sprintf("Failed on row %d", i)) + assert.Equal(t, expected, entity.Item.SoldTime, fmt.Sprintf("Failed on row %d", i)) + } +} + func Test_csvRow_getLabels(t *testing.T) { type fields struct { LabelStr string diff --git a/docs/docs/import-csv.md b/docs/docs/import-csv.md index ea32b8f..67b1e1d 100644 --- a/docs/docs/import-csv.md +++ b/docs/docs/import-csv.md @@ -52,5 +52,5 @@ Import RefLocation Labels Quantity Name Description Insured Serial Number Model | Type | Format | | ------- | --------------------------------------------------- | | String | Max 255 Characters unless otherwise specified | -| Date | YYYY-MM-DD | +| Date | MM/DD/YYYY | | Boolean | true or false, yes or no, 1 or 0 - case insensitive | diff --git a/frontend/components/global/DateTime.vue b/frontend/components/global/DateTime.vue index bc57acc..940ee3e 100644 --- a/frontend/components/global/DateTime.vue +++ b/frontend/components/global/DateTime.vue @@ -27,9 +27,9 @@ case DateTimeFormat.RELATIVE: return useTimeAgo(dt).value + useDateFormat(dt, " (MM-DD-YYYY)").value; case DateTimeFormat.LONG: - return useDateFormat(dt, "YYYY-MM-DD (dddd)").value; + return useDateFormat(dt, "MM-DD-YYYY (dddd)").value; case DateTimeFormat.SHORT: - return useDateFormat(dt, "YYYY-MM-DD").value; + return useDateFormat(dt, "MM-DD-YYYY").value; default: return ""; } diff --git a/frontend/lib/api/base/base-api.ts b/frontend/lib/api/base/base-api.ts index c8da034..b48d10b 100644 --- a/frontend/lib/api/base/base-api.ts +++ b/frontend/lib/api/base/base-api.ts @@ -1,16 +1,10 @@ import { Requests } from "../../requests"; -// < -// TGetResult, -// TPostData, -// TPostResult, -// TPutData = TPostData, -// TPutResult = TPostResult, -// TDeleteResult = void -// > type BaseApiType = { createdAt: string; updatedAt: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any; }; export function hasKey(obj: object, key: string): obj is Required { @@ -20,10 +14,11 @@ export function hasKey(obj: object, key: string): obj is Required { export function parseDate(obj: T, keys: Array = []): T { const result = { ...obj }; [...keys, "createdAt", "updatedAt"].forEach(key => { - // @ts-ignore - we are checking for the key above + // @ts-ignore - TS doesn't know that we're checking for the key above if (hasKey(result, key)) { - // @ts-ignore - we are guarding against this above - result[key] = new Date(result[key]); + // Ensure date like format YYYY/MM/DD - otherwise results will be 1 day off + const dateStr: string = result[key].split("T")[0].replace(/-/g, "/"); + result[key] = new Date(dateStr); } });