Fix/IMDB and comando-filmes date detection (#26)
* chg: fix: data and imdb detection * chg: fix: improve IMDB detection * chg: feat: add more audio strings
This commit is contained in:
@@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
)
|
||||
@@ -77,3 +78,115 @@ Servidor Via: Torrent
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_parseLocalizedDate(t *testing.T) {
|
||||
type args struct {
|
||||
datePublished string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want time.Time
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "should return date",
|
||||
args: args{
|
||||
datePublished: "12 de outubro de 2022",
|
||||
},
|
||||
want: time.Date(2022, 10, 12, 0, 0, 0, 0, time.UTC),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "should return date single digit",
|
||||
args: args{
|
||||
datePublished: "1 de outubro de 2022",
|
||||
},
|
||||
want: time.Date(2022, 10, 1, 0, 0, 0, 0, time.UTC),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := parseLocalizedDate(tt.args.datePublished)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("parseDate() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("parseDate() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getIMDBLink(t *testing.T) {
|
||||
type args struct {
|
||||
link string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "should return imdb link",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/title/tt1234567",
|
||||
},
|
||||
want: "https://www.imdb.com/title/tt1234567",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when end with /",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/title/tt1234567/",
|
||||
},
|
||||
want: "https://www.imdb.com/title/tt1234567/",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when end with /",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/title/tt1234567/",
|
||||
},
|
||||
want: "https://www.imdb.com/title/tt1234567/",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when it has a language",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/pt/title/tt18722864/",
|
||||
},
|
||||
want: "https://www.imdb.com/pt/title/tt18722864/",
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when it has a language",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/pt/title/tt34608980/",
|
||||
},
|
||||
want: "https://www.imdb.com/pt/title/tt34608980/",
|
||||
},
|
||||
{
|
||||
name: "should return error when link is invalid",
|
||||
args: args{
|
||||
link: "https://www.google.com",
|
||||
},
|
||||
want: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := getIMDBLink(tt.args.link)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("getIMDBLink() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("getIMDBLink() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user