From 3a5909f9779ff2978a7e12ff23bf934aa55c1dc6 Mon Sep 17 00:00:00 2001 From: Dmitry Ilvokhin Date: Tue, 18 Mar 2025 22:08:34 +0000 Subject: Sort and unique fetched flats There are cases (premium listings is one example), when there are duplicates in the fetched flats, unique them to avoid multiple notifications for the same property. --- parse_test.go | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) (limited to 'parse_test.go') diff --git a/parse_test.go b/parse_test.go index e8e0693..280e8a4 100644 --- a/parse_test.go +++ b/parse_test.go @@ -7,24 +7,56 @@ import ( "testing" ) -func TestParse(t *testing.T) { - filename := "2025-02-19-isle-of-dogs.html" +func TestParseBasic(t *testing.T) { + filename := "2025-02-19-basic.html" data, err := os.ReadFile(filepath.Join("testdata", filename)) if err != nil { - t.Errorf("Could not read %v", filename) + t.Fatalf("Could not read %v", filename) } want := []flat{ flat{ ID: 156522206, Price: "£2,500", }, + flat{ + ID: 157948184, + Price: "£2,400", + }, flat{ ID: 158462822, Price: "£3,000", + }} + got, err := parse(data) + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(got, want) { + t.Errorf("Parse failed: got: %v, want: %v", got, want) + } +} + +func TestParseDulicates(t *testing.T) { + filename := "2025-03-17-duplicates.html" + data, err := os.ReadFile(filepath.Join("testdata", filename)) + if err != nil { + t.Fatalf("Could not read %v", filename) + } + want := []flat{ + flat{ + ID: 158595710, + Price: "£2,000", }, flat{ - ID: 157948184, - Price: "£2,400", + ID: 158825903, + Price: "£2,500", + }, + flat{ + ID: 159476474, + Price: "£3,000", + }, + flat{ + ID: 159479504, + Price: "£890", }} got, err := parse(data) if err != nil { -- cgit v1.2.3-70-g09d2