Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download api/pkg/handlers/phone_api_key_handler_test.go from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 2.77 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/handlers/phone_api_key_handler_test.go
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway/api/pkg/handlers/phone_api_key_handler_test.go
-
curl -L -o phone_api_key_handler_test.go https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/handlers/phone_api_key_handler_test.go
2.77 kB
| //go:build integration | |
| package handlers | |
| import ( | |
| "context" | |
| "slices" | |
| "strings" | |
| "testing" | |
| "github.com/NdoleStudio/httpsms/pkg/entities" | |
| "github.com/NdoleStudio/httpsms/pkg/requests" | |
| "github.com/NdoleStudio/httpsms/pkg/responses" | |
| "github.com/jaswdr/faker/v2" | |
| "github.com/stretchr/testify/assert" | |
| ) | |
| func TestPhoneAPIKeyHandler_store(t *testing.T) { | |
| // Arrange | |
| fake := faker.New() | |
| payload := requests.PhoneAPIKeyStoreRequest{ | |
| Name: fake.RandomStringWithLength(20), | |
| } | |
| response := new(responses.PhoneAPIKeyResponse) | |
| // Act | |
| err := testClient(). | |
| Post(). | |
| Path("/v1/phone-api-keys"). | |
| BodyJSON(payload). | |
| ToJSON(response). | |
| Fetch(context.Background()) | |
| // Assert | |
| assert.Nil(t, err) | |
| assert.NotEmpty(t, response.Data.ID) | |
| assert.True(t, strings.HasPrefix(response.Data.APIKey, "pk_")) | |
| assert.Equal(t, payload.Name, response.Data.Name) | |
| assert.True(t, len(response.Data.PhoneNumbers) == 0) | |
| assert.True(t, len(response.Data.PhoneIDs) == 0) | |
| // Teardown | |
| _ = testClient(). | |
| Delete(). | |
| Path("/v1/phone-api-keys/" + response.Data.ID.String()). | |
| Fetch(context.Background()) | |
| } | |
| func TestPhoneAPIKeyHandler_delete(t *testing.T) { | |
| // Arrange | |
| fake := faker.New() | |
| payload := requests.PhoneAPIKeyStoreRequest{ | |
| Name: fake.RandomStringWithLength(20), | |
| } | |
| // Act | |
| response := new(responses.PhoneAPIKeyResponse) | |
| _ = testClient(). | |
| Post(). | |
| Path("/v1/phone-api-keys"). | |
| BodyJSON(payload). | |
| ToJSON(response). | |
| Fetch(context.Background()) | |
| err := testClient(). | |
| Delete(). | |
| Path("/v1/phone-api-keys/" + response.Data.ID.String()). | |
| Fetch(context.Background()) | |
| // Assert | |
| assert.Nil(t, err) | |
| keys := new(responses.PhoneAPIKeysResponse) | |
| _ = testClient(). | |
| Path("/v1/phone-api-keys"). | |
| ToJSON(response). | |
| Fetch(context.Background()) | |
| assert.Equal(t, -1, slices.IndexFunc(keys.Data, func(key *entities.PhoneAPIKey) bool { | |
| return key.ID == response.Data.ID | |
| })) | |
| } | |
| func TestPhoneAPIKeyHandler_index(t *testing.T) { | |
| // Arrange | |
| fake := faker.New() | |
| createResponse := new(responses.PhoneAPIKeyResponse) | |
| response := new(responses.PhoneAPIKeysResponse) | |
| payload := requests.PhoneAPIKeyStoreRequest{ | |
| Name: fake.RandomStringWithLength(20), | |
| } | |
| // Act | |
| _ = testClient(). | |
| Post(). | |
| Path("/v1/phone-api-keys"). | |
| BodyJSON(payload). | |
| ToJSON(createResponse). | |
| Fetch(context.Background()) | |
| err := testClient(). | |
| Path("/v1/phone-api-keys"). | |
| ToJSON(response). | |
| Fetch(context.Background()) | |
| // Assert | |
| assert.Nil(t, err) | |
| assert.NotEmpty(t, response.Data) | |
| assert.NotEqual(t, -1, slices.IndexFunc(response.Data, func(key *entities.PhoneAPIKey) bool { | |
| return key.ID == createResponse.Data.ID | |
| })) | |
| // Teardown | |
| _ = testClient(). | |
| Delete(). | |
| Path("/v1/phone-api-keys/" + createResponse.Data.ID.String()). | |
| Fetch(context.Background()) | |
| } | |