(t *testing.T)
| 6787 | } |
| 6788 | |
| 6789 | func TestGetAPIKeyByKey_Mock(t *testing.T) { |
| 6790 | cnf := &config.Configuration{ |
| 6791 | Redis: config.RedisConfig{Dns: "localhost:6379"}, |
| 6792 | Queue: config.QueueConfig{ |
| 6793 | WebhookQueue: "webhook_queue", |
| 6794 | TransactionQueue: "transaction_queue", |
| 6795 | NumberOfQueues: 1, |
| 6796 | }, |
| 6797 | } |
| 6798 | config.ConfigStore.Store(cnf) |
| 6799 | |
| 6800 | t.Run("Success", func(t *testing.T) { |
| 6801 | mockDS := new(mocks.MockDataSource) |
| 6802 | keyString := "abc123xyz" |
| 6803 | expectedKey := &model.APIKey{ |
| 6804 | APIKeyID: "key_123", |
| 6805 | Key: keyString, |
| 6806 | Name: "Test Key", |
| 6807 | } |
| 6808 | |
| 6809 | mockDS.On("GetAPIKey", mock.Anything, keyString).Return(expectedKey, nil) |
| 6810 | |
| 6811 | ledgerforge := &LedgerForge{datasource: mockDS, config: cnf} |
| 6812 | result, err := ledgerforge.GetAPIKeyByKey(context.Background(), keyString) |
| 6813 | |
| 6814 | assert.NoError(t, err) |
| 6815 | assert.NotNil(t, result) |
| 6816 | assert.Equal(t, keyString, result.Key) |
| 6817 | mockDS.AssertExpectations(t) |
| 6818 | }) |
| 6819 | |
| 6820 | t.Run("Not found", func(t *testing.T) { |
| 6821 | mockDS := new(mocks.MockDataSource) |
| 6822 | mockDS.On("GetAPIKey", mock.Anything, "invalid").Return((*model.APIKey)(nil), fmt.Errorf("not found")) |
| 6823 | |
| 6824 | ledgerforge := &LedgerForge{datasource: mockDS, config: cnf} |
| 6825 | result, err := ledgerforge.GetAPIKeyByKey(context.Background(), "invalid") |
| 6826 | |
| 6827 | assert.Error(t, err) |
| 6828 | assert.Nil(t, result) |
| 6829 | mockDS.AssertExpectations(t) |
| 6830 | }) |
| 6831 | } |
| 6832 | |
| 6833 | func TestUpdateLastUsed_Mock(t *testing.T) { |
| 6834 | cnf := &config.Configuration{ |
nothing calls this directly
no test coverage detected