Add GetAddressById
This commit is contained in:
parent
4b61c87b55
commit
258035833b
@ -50,3 +50,12 @@ func (repo AddressRepository) GetOrCreateAddressInTransaction(tx *sqlx.Tx, addre
|
||||
|
||||
return addressId, getErr
|
||||
}
|
||||
|
||||
func (repo AddressRepository) GetAddressById(db *postgres.DB, id int) (string, error){
|
||||
var address string
|
||||
getErr := db.Get(&address, `SELECT address FROM public.addresses WHERE id = $1`, id)
|
||||
if getErr != nil {
|
||||
return "", getErr
|
||||
}
|
||||
return address, nil
|
||||
}
|
||||
|
@ -146,4 +146,22 @@ var _ = Describe("address lookup", func() {
|
||||
Expect(upperAddressId).To(Equal(mixedCaseAddressId))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("GetAddressById", func() {
|
||||
It("gets and address by it's id", func() {
|
||||
addressId, createErr := repo.GetOrCreateAddress(db, address)
|
||||
Expect(createErr).NotTo(HaveOccurred())
|
||||
|
||||
actualAddress, getErr := repo.GetAddressById(db, addressId)
|
||||
Expect(getErr).NotTo(HaveOccurred())
|
||||
Expect(actualAddress).To(Equal(address))
|
||||
})
|
||||
|
||||
It("returns an error if the id doesn't exist", func() {
|
||||
_, getErr := repo.GetAddressById(db, 0)
|
||||
Expect(getErr).To(HaveOccurred())
|
||||
Expect(getErr).To(MatchError("sql: no rows in result set"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user