MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestCreateAPIKey_Mock

Function TestCreateAPIKey_Mock

transaction_test.go:6659–6708  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6657}
6658
6659func TestCreateAPIKey_Mock(t *testing.T) {
6660 cnf := &config.Configuration{
6661 Redis: config.RedisConfig{Dns: "localhost:6379"},
6662 Queue: config.QueueConfig{
6663 WebhookQueue: "webhook_queue",
6664 TransactionQueue: "transaction_queue",
6665 NumberOfQueues: 1,
6666 },
6667 }
6668 config.ConfigStore.Store(cnf)
6669
6670 t.Run("Success", func(t *testing.T) {
6671 mockDS := new(mocks.MockDataSource)
6672 name := "Test Key"
6673 ownerID := "owner_123"
6674 scopes := []string{"read", "write"}
6675 expiresAt := time.Now().Add(24 * time.Hour)
6676
6677 expectedKey := &model.APIKey{
6678 APIKeyID: "api_key_123",
6679 Name: name,
6680 OwnerID: ownerID,
6681 Scopes: scopes,
6682 ExpiresAt: expiresAt,
6683 }
6684
6685 mockDS.On("CreateAPIKey", mock.Anything, name, ownerID, scopes, expiresAt).Return(expectedKey, nil)
6686
6687 ledgerforge := &LedgerForge{datasource: mockDS, config: cnf}
6688 result, err := ledgerforge.CreateAPIKey(context.Background(), name, ownerID, scopes, expiresAt)
6689
6690 assert.NoError(t, err)
6691 assert.NotNil(t, result)
6692 assert.Equal(t, name, result.Name)
6693 mockDS.AssertExpectations(t)
6694 })
6695
6696 t.Run("Error", func(t *testing.T) {
6697 mockDS := new(mocks.MockDataSource)
6698 mockDS.On("CreateAPIKey", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
6699 Return((*model.APIKey)(nil), fmt.Errorf("creation failed"))
6700
6701 ledgerforge := &LedgerForge{datasource: mockDS, config: cnf}
6702 result, err := ledgerforge.CreateAPIKey(context.Background(), "name", "owner", []string{}, time.Now())
6703
6704 assert.Error(t, err)
6705 assert.Nil(t, result)
6706 mockDS.AssertExpectations(t)
6707 })
6708}
6709
6710func TestListAPIKeys_Mock(t *testing.T) {
6711 cnf := &config.Configuration{

Callers

nothing calls this directly

Calls 2

CreateAPIKeyMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected