fixstmt

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

convert_test.go (3635B)


      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 		{"2021061230123456.pdf", "Shinsei Bank"},
     17 	}
     18 	for _, tc := range testCases {
     19 		got, err := convert.ConverterForFile(tc.name)
     20 		if err != nil {
     21 			t.Errorf("Failed to get converter for file %s", tc.name)
     22 		} else if got.Type() != tc.want {
     23 			t.Errorf("In(%s) = %s; want %s", tc.name, got.Type(), tc.want)
     24 		}
     25 	}
     26 }
     27 
     28 func TestConverterForFileWithUnknownType(t *testing.T) {
     29 	got, err := convert.ConverterForFile("document.pdf")
     30 	if err == nil {
     31 		t.Errorf("Expected error for file document.pdf")
     32 	}
     33 	if got != nil {
     34 		t.Errorf("In(document.pdf) = %s; want nil", got.Type())
     35 	}
     36 }
     37 
     38 func TestRbcDirectInvesting(t *testing.T) {
     39 	testCases := []struct {
     40 		name string
     41 		want string
     42 	}{
     43 		{"123456789-2007Jan10-2007feb09.pdf", "2007-02-09.pdf"},
     44 		{"987654321-2020mAr31-2020apR30.pdf", "2020-04-30.pdf"},
     45 		{"123456-2021MAY01-2021mAY31.pdf", "2021-05-31.pdf"},
     46 		{"8905672341-2022Jun21-2022Jul20.pdf", "2022-07-20.pdf"},
     47 		{"2345678901-2022Aug15-2022Sep14.pdf", "2022-09-14.pdf"},
     48 		{"2345678901-2022Oct31-2022Nov30.pdf", "2022-11-30.pdf"},
     49 		{"2345678901-2022Nov29-2023Jan28.pdf", "2023-01-28.pdf"},
     50 	}
     51 	converter := convert.RbcDirectInvesting{}
     52 	for _, tc := range testCases {
     53 		got, err := converter.Convert(tc.name)
     54 		if err != nil {
     55 			t.Errorf("Failed to convert file %s", tc.name)
     56 		} else if got != tc.want {
     57 			t.Errorf("In(%s) = %s; want %s", tc.name, got, tc.want)
     58 		}
     59 	}
     60 }
     61 
     62 func TestAppleCard(t *testing.T) {
     63 	testCases := []struct {
     64 		name string
     65 		want string
     66 	}{
     67 		{"Apple Card Statement - January 2020.pdf", "2020-01.pdf"},
     68 		{"Apple Card Statement - February 2020.pdf", "2020-02.pdf"},
     69 		{"Apple Card Statement - March 2020.pdf", "2020-03.pdf"},
     70 		{"Apple Card Statement - April 2020.pdf", "2020-04.pdf"},
     71 		{"Apple Card Statement - May 2020.pdf", "2020-05.pdf"},
     72 		{"Apple Card Statement - June 2020.pdf", "2020-06.pdf"},
     73 		{"Apple Card Statement - July 2020.pdf", "2020-07.pdf"},
     74 		{"Apple Card Statement - August 2020.pdf", "2020-08.pdf"},
     75 		{"Apple Card Statement - September 2020.pdf", "2020-09.pdf"},
     76 		{"Apple Card Statement - October 2020.pdf", "2020-10.pdf"},
     77 		{"Apple Card Statement - November 2020.pdf", "2020-11.pdf"},
     78 		{"Apple Card Statement - December 2020.pdf", "2020-12.pdf"},
     79 	}
     80 	converter := convert.AppleCard{}
     81 	for _, tc := range testCases {
     82 		got, err := converter.Convert(tc.name)
     83 		if err != nil {
     84 			t.Errorf("Failed to convert file %s", tc.name)
     85 		} else if got != tc.want {
     86 			t.Errorf("In(%s) = %s; want %s", tc.name, got, tc.want)
     87 		}
     88 	}
     89 }
     90 
     91 func TestShinseiBank(t *testing.T) {
     92 	testCases := []struct {
     93 		name string
     94 		want string
     95 	}{
     96 		{"2005011230123456", "2005-01.pdf"},
     97 		{"2016021230123456", "2016-02.pdf"},
     98 		{"2027031230123456", "2027-03.pdf"},
     99 		{"2038041230123456", "2038-04.pdf"},
    100 		{"2049051230123456", "2049-05.pdf"},
    101 		{"2050061230123456", "2050-06.pdf"},
    102 		{"2061071230123456", "2061-07.pdf"},
    103 		{"2072081230123456", "2072-08.pdf"},
    104 		{"2083091230123456", "2083-09.pdf"},
    105 		{"2094101230123456", "2094-10.pdf"},
    106 		{"2105111230123456", "2105-11.pdf"},
    107 		{"2116121230123456", "2116-12.pdf"},
    108 	}
    109 	converter := convert.ShinseiBank{}
    110 	for _, tc := range testCases {
    111 		got, err := converter.Convert(tc.name)
    112 		if err != nil {
    113 			t.Errorf("Failed to convert file %s: %s", tc.name, err)
    114 		} else if got != tc.want {
    115 			t.Errorf("In(%s) = %s; want %s", tc.name, got, tc.want)
    116 		}
    117 	}
    118 }