This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t.Run("returns an error on failure to get customer booking count", func(t *testing.T) { | |
var customerID uint = 1 | |
var want = errors.New("oh no!") | |
ctrl := gomock.NewController(t) | |
mockCustomerGetter := NewMockCustomerGetter(ctrl) | |
mockCustomerBookingCounter := NewMockCustomerGetter(ctrl) | |
mockCustomerGetter.EXPECT().GetCustomer(customerID).Return(entities.Customer{}, nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package usecases | |
import "github.com/example/go-abstractions/entities" | |
type CustomerGetter interface { | |
GetCustomer(customerID uint) (entities.Customer, error) | |
} | |
type CustomerBookingsCounter interface { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ackage bookings | |
type Repository struct { | |
// in reality, this client will likely be something we generate from a | |
// schema, or implement ourselves if needs be. Its not discussed here for | |
// conciseness | |
client bookingsServiceClient | |
} | |
type booking struct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package entities | |
type Customer struct { | |
ID uint | |
FirstName string | |
Postcode string | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package usecases | |
import "github.com/example/go-abstractions/entities" | |
type CustomerGetter interface { | |
GetCustomer(customerID uint) (entities.Customer, error) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package customers | |
import "github.com/example/go-abstractions/entities" | |
// representation of a fictional database customer. | |
type customerData struct { | |
ID uint `db:"id"` | |
FirstName string `db:"name"` | |
Postcode string `db:"postcode"` | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package customers | |
type Repository struct { | |
// This is where whatever the repository will use to access the DB will live | |
// as an unexported field. Nothing groundbreaking here. | |
somethingToAccessTheDB interface{} | |
} | |
// NewRepository will return a new instance of the customers.Repository. I've | |
// not outfitted it with actual DB connection logic so as to keep this article |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const qxrecs = require('qxrecs'); | |
/* | |
Configure the module with your company name, unique token | |
and communication protocol (currently either https or wss) | |
*/ | |
qxrecs.Configure("my_company", "my_token", "https"); | |
//Insert some products using callbacks. Can be used with multiple items | |
qxrecs.PostProducts([{itemid: "A" }], (err, body) => { |