From 84f62d92b56e7b7be0ff24efbfd37b1f4b4cb370 Mon Sep 17 00:00:00 2001 From: Euan Date: Sun, 29 Sep 2024 22:15:03 +0100 Subject: [PATCH 1/2] we test...at dawn --- backend/dbtools/dbtools_test.go | 1 - backend/endpoints.go | 3 -- backend/lifter/instagram.go | 39 --------------------- backend/lifter/instagram_test.go | 53 ----------------------------- backend/lifterdata/igdatabase.go | 8 ----- backend/lifterdata/ighandles.csv | 8 ----- backend/structs/structs.go | 1 - backend/utilities/utilities_test.go | 35 ------------------- 8 files changed, 148 deletions(-) delete mode 100644 backend/lifter/instagram.go delete mode 100644 backend/lifter/instagram_test.go delete mode 100644 backend/lifterdata/igdatabase.go delete mode 100644 backend/lifterdata/ighandles.csv diff --git a/backend/dbtools/dbtools_test.go b/backend/dbtools/dbtools_test.go index c98a92b32..62b65cb1b 100644 --- a/backend/dbtools/dbtools_test.go +++ b/backend/dbtools/dbtools_test.go @@ -220,7 +220,6 @@ func Test_assignStruct(t *testing.T) { Total: 330, Sinclair: 0, Federation: "BWL", - Instagram: "", }, }} for _, tt := range tests { diff --git a/backend/endpoints.go b/backend/endpoints.go index afe9c5e7b..0c5163411 100644 --- a/backend/endpoints.go +++ b/backend/endpoints.go @@ -22,9 +22,6 @@ var DiscoKaren discordbot.DiscordBot // LeaderboardData is a global variable that is used to hold the leaderboard data. var LeaderboardData structs.LeaderboardData -// this is remnant of the instagram linking code -// var lifterData = lifter.Build() - // QueryCache is a global variable that is used to cache queries for the leaderboard endpoint. var QueryCache dbtools.QueryCache diff --git a/backend/lifter/instagram.go b/backend/lifter/instagram.go deleted file mode 100644 index 2f1596963..000000000 --- a/backend/lifter/instagram.go +++ /dev/null @@ -1,39 +0,0 @@ -package lifter - -import ( - igDatabase "backend/lifterdata" - "backend/utilities" - "io/fs" - "log" -) - -func CheckUserList(lifterName string, lifterProfiles map[string]string) (bool, string) { - if utilities.MapContains(lifterName, lifterProfiles) { - return true, lifterProfiles[lifterName] - } - return false, "" -} - -func Build() *map[string]string { - var lifterGrams [][]string - var lifterGramsMap = make(map[string]string) - func() { - fileHandle, err := igDatabase.InstagramDatabase.Open("ighandles.csv") - if err != nil { - log.Fatal(err) - } - defer func(fileHandle fs.File) { - err := fileHandle.Close() - if err != nil { - log.Fatal(err) - } - }(fileHandle) - gramData := utilities.LoadCsvFile(fileHandle) - lifterGrams = append(lifterGrams, gramData...) - }() - - for _, gram := range lifterGrams { - lifterGramsMap[gram[0]] = gram[1] - } - return &lifterGramsMap -} diff --git a/backend/lifter/instagram_test.go b/backend/lifter/instagram_test.go deleted file mode 100644 index 6a80eab51..000000000 --- a/backend/lifter/instagram_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package lifter - -import ( - "reflect" - "testing" -) - -func TestCheckUserList(t *testing.T) { - lifterProfiles := make(map[string]string) - lifterProfiles["Euan Meston"] = "scream_and_jerk" - - type args struct { - lifterName string - } - tests := []struct { - name string - args args - want bool - want1 string - }{ - {name: "Expected Match", args: args{lifterName: "Euan Meston"}, want: true, want1: "scream_and_jerk"}, - {"No User Exists", args{lifterName: "Jesus Christ"}, false, ""}, - {"No Match on Case", args{lifterName: "euan meston"}, false, ""}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, got1 := CheckUserList(tt.args.lifterName, lifterProfiles) - if got != tt.want { - t.Errorf("CheckUserList() got = %v, want %v", got, tt.want) - } - if got1 != tt.want1 { - t.Errorf("CheckUserList() got1 = %v, want %v", got1, tt.want1) - } - }) - } -} - -func TestBuild(t *testing.T) { - tests := []struct { - name string - want *map[string]string - }{ - // test build function and verify that it return a pointer to a map - {"Build", &map[string]string{"Euan Meston": "scream_and_jerk"}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := Build(); reflect.TypeOf(got) != reflect.TypeOf(tt.want) { - t.Errorf("Build() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/backend/lifterdata/igdatabase.go b/backend/lifterdata/igdatabase.go deleted file mode 100644 index 619b1eff5..000000000 --- a/backend/lifterdata/igdatabase.go +++ /dev/null @@ -1,8 +0,0 @@ -package lifterdata - -import ( - "embed" -) - -//go:embed *.csv -var InstagramDatabase embed.FS diff --git a/backend/lifterdata/ighandles.csv b/backend/lifterdata/ighandles.csv deleted file mode 100644 index 0acb292ca..000000000 --- a/backend/lifterdata/ighandles.csv +++ /dev/null @@ -1,8 +0,0 @@ -lifter,instagram -Euan Meston,scream_and_jerk -KRYSTAL CAMPBELL,da.real.krys -TALAKHADZE Lasha,talakhadzelasha_official -Benedict Millson,mrbigfriday -Stefano Cataldi,stefanotheweightlifter -Harry Nelms,13harry1999 -Khrystopher Speed,kdotspeed \ No newline at end of file diff --git a/backend/structs/structs.go b/backend/structs/structs.go index 2ec707509..ae87bc266 100644 --- a/backend/structs/structs.go +++ b/backend/structs/structs.go @@ -90,7 +90,6 @@ type Entry struct { Total float32 `json:"total"` Sinclair float32 `json:"sinclair"` Federation string `json:"country"` - Instagram string `json:"instagram"` } type LeaderboardResponse struct { diff --git a/backend/utilities/utilities_test.go b/backend/utilities/utilities_test.go index 394c0b378..b6e3ca238 100644 --- a/backend/utilities/utilities_test.go +++ b/backend/utilities/utilities_test.go @@ -1,10 +1,6 @@ package utilities import ( - igDatabase "backend/lifterdata" - "io" - "io/fs" - "log" "reflect" "testing" "time" @@ -59,37 +55,6 @@ func TestFloat(t *testing.T) { } } -func TestLoadCsvFile(t *testing.T) { - fileHandle, err := igDatabase.InstagramDatabase.Open("ighandles.csv") - if err != nil { - log.Fatal(err) - } - defer func(fileHandle fs.File) { - err := fileHandle.Close() - if err != nil { - log.Fatal(err) - } - }(fileHandle) - - type args struct { - file io.Reader - } - tests := []struct { - name string - args args - wantedTypeOf [][]string - }{ - {name: "LoadCsvFile", args: args{file: fileHandle}, wantedTypeOf: [][]string{}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := LoadCsvFile(tt.args.file); !reflect.DeepEqual(reflect.TypeOf(got), reflect.TypeOf(tt.wantedTypeOf)) { - t.Errorf("LoadCsvFile() = %v, want %v", got, tt.wantedTypeOf) - } - }) - } -} - func TestMapContains(t *testing.T) { type args struct { StrQuery string From 380b8cfc4f9452b3bff0fe9ee2407db3baa149d5 Mon Sep 17 00:00:00 2001 From: Euan Date: Mon, 30 Sep 2024 20:17:36 +0100 Subject: [PATCH 2/2] fe tweaks and tests are playing ball --- .../fetchLifterData/fetchLifterDataTypes.d.ts | 41 +++++++++---------- frontend/components/molecules/dataTable.tsx | 30 +++++--------- 2 files changed, 30 insertions(+), 41 deletions(-) diff --git a/frontend/api/fetchLifterData/fetchLifterDataTypes.d.ts b/frontend/api/fetchLifterData/fetchLifterDataTypes.d.ts index 832819967..887fff781 100644 --- a/frontend/api/fetchLifterData/fetchLifterDataTypes.d.ts +++ b/frontend/api/fetchLifterData/fetchLifterDataTypes.d.ts @@ -1,24 +1,23 @@ export type LifterResult = { - event: string; - date: string; - gender: string; - lifter_name: string; - bodyweight: number; - snatch_1: number; - snatch_2: number; - snatch_3: number; - cj_1: number; - cj_2: number; - cj_3: number; - best_snatch: number; - best_cj: number; - total: number; - sinclair: number; - country: string; - instagram: string; - }; + event: string + date: string + gender: string + lifter_name: string + bodyweight: number + snatch_1: number + snatch_2: number + snatch_3: number + cj_1: number + cj_2: number + cj_3: number + best_snatch: number + best_cj: number + total: number + sinclair: number + country: string +} export type LeaderboardResult = { - size: number; - data: LifterResult[]; -} \ No newline at end of file + size: number + data: LifterResult[] +} diff --git a/frontend/components/molecules/dataTable.tsx b/frontend/components/molecules/dataTable.tsx index e792d7553..a3126da77 100644 --- a/frontend/components/molecules/dataTable.tsx +++ b/frontend/components/molecules/dataTable.tsx @@ -13,7 +13,10 @@ import { CgProfile } from 'react-icons/cg' import { AllDetails } from './allDetails' -import { LifterResult, LeaderboardResult } from '@/api/fetchLifterData/fetchLifterDataTypes' +import { + LifterResult, + LeaderboardResult, +} from '@/api/fetchLifterData/fetchLifterDataTypes' export const DataTable = ({ lifters, @@ -23,15 +26,8 @@ export const DataTable = ({ openLifterGraphHandler: (lifterName: string) => void }) => { const generateLifterRow = (lifter: LifterResult, lifterNo: number) => { - const { - lifter_name, - instagram, - country, - best_snatch, - best_cj, - total, - sinclair, - } = lifter + const { lifter_name, country, best_snatch, best_cj, total, sinclair } = + lifter const lifter_page = 'lifter?name=' + lifter_name return ( @@ -39,21 +35,15 @@ export const DataTable = ({ {lifterNo} {lifter_name} - - {instagram && ( - - - - )} {country} {best_snatch}