summaryrefslogtreecommitdiff
path: root/parse_test.go
diff options
context:
space:
mode:
authorDmitry Ilvokhin <d@ilvokhin.com>2025-03-18 22:08:34 +0000
committerDmitry Ilvokhin <d@ilvokhin.com>2025-03-18 22:08:34 +0000
commit3a5909f9779ff2978a7e12ff23bf934aa55c1dc6 (patch)
tree68c9a3558939d8f849ef2eacbc777a6075b2aaeb /parse_test.go
parentbbf5d9d99aa6131dccada8908b770ac10f52be59 (diff)
downloadflatbot-3a5909f9779ff2978a7e12ff23bf934aa55c1dc6.tar.gz
flatbot-3a5909f9779ff2978a7e12ff23bf934aa55c1dc6.tar.bz2
flatbot-3a5909f9779ff2978a7e12ff23bf934aa55c1dc6.zip
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.
Diffstat (limited to 'parse_test.go')
-rw-r--r--parse_test.go42
1 files changed, 37 insertions, 5 deletions
diff --git a/parse_test.go b/parse_test.go
index e8e0693..280e8a4 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -7,11 +7,11 @@ 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{
@@ -19,12 +19,44 @@ func TestParse(t *testing.T) {
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 {