fixrbc

Tool to rename RBC statements to yyyy-mm-dd format
git clone https://git.bracken.jp/fixrbc.git
Log | Files | Refs | LICENSE

convert_test.go (2742B)


      1 package convert_test
      2 
      3 import (
      4 	"testing"
      5 
      6 	"git.bracken.jp/fixstmt/convert"
      7 )
      8 
      9 func TestConverterForFile(t *testing.T) {
     10 	testCases := []struct {
     11 		name string
     12 		want string
     13 	}{
     14 		{"123456789-2007jAn10-2007FeB09.pdf", "RBC Direct Investing"},
     15 		{"Apple Card Statement - JaNUarY 2020.pdf", "Apple Card"},
     16 	}
     17 	for _, tc := range testCases {
     18 		got, err := convert.ConverterForFile(tc.name)
     19 		if err != nil {
     20 			t.Errorf("Failed to get converter for file %s", tc.name)
     21 		} else if got.Type() != tc.want {
     22 			t.Errorf("In(%s) = %s; want %s", tc.name, got.Type(), tc.want)
     23 		}
     24 	}
     25 }
     26 
     27 func TestConverterForFileWithUnknownType(t *testing.T) {
     28 	got, err := convert.ConverterForFile("document.pdf")
     29 	if err == nil {
     30 		t.Errorf("Expected error for file document.pdf")
     31 	}
     32 	if got != nil {
     33 		t.Errorf("In(document.pdf) = %s; want nil", got.Type())
     34 	}
     35 }
     36 
     37 func TestRbcDirectInvesting(t *testing.T) {
     38 	testCases := []struct {
     39 		name string
     40 		want string
     41 	}{
     42 		{"123456789-2007Jan10-2007feb09.pdf", "2007-02-09.pdf"},
     43 		{"987654321-2020mAr31-2020apR30.pdf", "2020-04-30.pdf"},
     44 		{"123456-2021MAY01-2021mAY31.pdf", "2021-05-31.pdf"},
     45 		{"8905672341-2022Jun21-2022Jul20.pdf", "2022-07-20.pdf"},
     46 		{"2345678901-2022Aug15-2022Sep14.pdf", "2022-09-14.pdf"},
     47 		{"2345678901-2022Oct31-2022Nov30.pdf", "2022-11-30.pdf"},
     48 		{"2345678901-2022Nov29-2023Jan28.pdf", "2023-01-28.pdf"},
     49 	}
     50 	converter := convert.RbcDirectInvesting{}
     51 	for _, tc := range testCases {
     52 		got, err := converter.Convert(tc.name)
     53 		if err != nil {
     54 			t.Errorf("Failed to convert file %s", tc.name)
     55 		} else if got != tc.want {
     56 			t.Errorf("In(%s) = %s; want %s", tc.name, got, tc.want)
     57 		}
     58 	}
     59 }
     60 
     61 func TestAppleCard(t *testing.T) {
     62 	testCases := []struct {
     63 		name string
     64 		want string
     65 	}{
     66 		{"Apple Card Statement - January 2020.pdf", "2020-01.pdf"},
     67 		{"Apple Card Statement - February 2020.pdf", "2020-02.pdf"},
     68 		{"Apple Card Statement - March 2020.pdf", "2020-03.pdf"},
     69 		{"Apple Card Statement - April 2020.pdf", "2020-04.pdf"},
     70 		{"Apple Card Statement - May 2020.pdf", "2020-05.pdf"},
     71 		{"Apple Card Statement - June 2020.pdf", "2020-06.pdf"},
     72 		{"Apple Card Statement - July 2020.pdf", "2020-07.pdf"},
     73 		{"Apple Card Statement - August 2020.pdf", "2020-08.pdf"},
     74 		{"Apple Card Statement - September 2020.pdf", "2020-09.pdf"},
     75 		{"Apple Card Statement - October 2020.pdf", "2020-10.pdf"},
     76 		{"Apple Card Statement - November 2020.pdf", "2020-11.pdf"},
     77 		{"Apple Card Statement - December 2020.pdf", "2020-12.pdf"},
     78 	}
     79 	converter := convert.AppleCard{}
     80 	for _, tc := range testCases {
     81 		got, err := converter.Convert(tc.name)
     82 		if err != nil {
     83 			t.Errorf("Failed to convert file %s", tc.name)
     84 		} else if got != tc.want {
     85 			t.Errorf("In(%s) = %s; want %s", tc.name, got, tc.want)
     86 		}
     87 	}
     88 }