Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
fix fourcube/goiban-service#9
Browse files Browse the repository at this point in the history
  • Loading branch information
fourcube committed Feb 7, 2017
1 parent c6d3f28 commit a97a7e8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
3 changes: 1 addition & 2 deletions bank_code_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package goiban
import (
"database/sql"
"strconv"
"strings"
)

var (
Expand Down Expand Up @@ -57,7 +56,7 @@ func ValidateBankCode(iban *Iban, intermediateResult *ValidationResult, db *sql.
}

bankCode := iban.bban[0:length]
bankCode = strings.TrimLeft(bankCode, "0")
//bankCode = strings.TrimLeft(bankCode, "0")

var res int
err := SELECT_BY_BANK_CODE_STMT.QueryRow(bankCode, iban.countryCode).Scan(&res)
Expand Down
3 changes: 3 additions & 0 deletions countries/ch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type SwitzerlandFileEntry struct {
func SwitzerlandRowToEntry(row []string, bankCodeLengthMap map[string]int) SwitzerlandFileEntry {
bankCode, err := strconv.Atoi(row[1])
bankCodeNew, errNew := strconv.Atoi(row[3])
bankCodeLength := bankCodeLengthMap["CH"]
bankCodeStr := ""

if err == nil {
Expand All @@ -48,6 +49,8 @@ func SwitzerlandRowToEntry(row []string, bankCodeLengthMap map[string]int) Switz
bankCodeStr = strconv.Itoa(bankCodeNew)
}

bankCodeStr = PadLeftZero(bankCodeStr, bankCodeLength)

return SwitzerlandFileEntry{
Name: strings.TrimSpace(row[12]),
Bankcode: bankCodeStr,
Expand Down
6 changes: 1 addition & 5 deletions countries/helpers.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package countries

import "strconv"

func PadLeftZero(n int, length int) string {
s := strconv.Itoa(n)

func PadLeftZero(s string, length int) string {
for len(s) < length {
s = "0" + s
}
Expand Down
4 changes: 1 addition & 3 deletions external_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
"fmt"
"log"

"strings"

co "github.com/fourcube/goiban/countries"
"github.com/tealeg/xlsx"
)
Expand Down Expand Up @@ -94,7 +92,7 @@ func getBankInformationByCountryAndBankCodeFromDb(countryCode string, bankCode s

var dbBankcode, dbName, dbZip, dbCity, dbBic string

bankCode = strings.TrimLeft(bankCode, "0")
//bankCode = strings.TrimLeft(bankCode, "0")

err := SELECT_BANK_INFORMATION_STMT.QueryRow(bankCode, countryCode).Scan(&dbBankcode, &dbName, &dbZip, &dbCity, &dbBic)

Expand Down
7 changes: 7 additions & 0 deletions external_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ func TestCanLoadBankInfoFromDatabase(t *testing.T) {
}
}

func TestCanLoadBankInfoFromDatabaseLeadingZeros(t *testing.T) {
bankInfo := getBankInformationByCountryAndBankCodeFromDb("BE", "001", db)
if bankInfo == nil {
t.Errorf("Cannot load data from db. Is it empty?")
}
}

func TestCanReadFromBelgiumXLSX(t *testing.T) {
ch := make(chan interface{})
go ReadFileToEntries("test/belgium.xlsx", &co.BelgiumFileEntry{}, ch)
Expand Down
4 changes: 2 additions & 2 deletions iban_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestCanGenerateIBANFromValidData(t *testing.T) {
}

if result.Data != "BE68539007547034" {
t.Errorf("expected result iban to match %v != %v", result.Data, "BE68539007547034")
t.Errorf("expected result iban to match, %v != %v", result.Data, "BE68539007547034")
}
}

Expand All @@ -202,6 +202,6 @@ func TestCanGenerateIBANFromValidDataEnsureCheckdigitsLeadingZeroPresent(t *test
}

if result.Data != "DE22000000010000000009" {
t.Errorf("expected result iban to match %v != %v", result.Data, "DE0819")
t.Errorf("expected result iban to match, %v != %v", result.Data, "DE22000000010000000009")
}
}

0 comments on commit a97a7e8

Please sign in to comment.