package privilege import ( "fmt" "github.com/gofiber/fiber/v2" "github.com/stretchr/testify/assert" "testing" "time" ) func TestPublishPrivileges(t *testing.T) { client := Client{ URL: "http://localhost:8001", ServiceName: "key", Privileges: []Privilege{ { ID: "1", PrivilegeID: "test1", Name: "Test 1", ServiceKey: "key", Description: "This is a test", Type: "count", Value: "100", Price: 10.0, Amount: 5, IsDeleted: false, CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: time.Time{}, }, { ID: "2", PrivilegeID: "test2", Name: "Test 2", ServiceKey: "key2", Description: "This is a test", Type: "count", Value: "100", Price: 15.0, Amount: 3, IsDeleted: false, CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: time.Time{}, }, }, } fiberClient := fiber.Client{} controller := NewPrivilege(client, &fiberClient) err := controller.PublishPrivileges() assert.Nil(t, err) } func TestGetActualPrivileges(t *testing.T) { client := Client{ URL: "http://localhost:8001", ServiceName: "key", Privileges: []Privilege{}, } fiberClient := fiber.Client{} controller := NewPrivilege(client, &fiberClient) privileges, err := controller.getActualPrivileges() fmt.Println(privileges) assert.Nil(t, err) assert.NotNil(t, privileges) } func TestUpdatePrivileges(t *testing.T) { client := Client{ URL: "http://localhost:8001", ServiceName: "key", Privileges: []Privilege{ { ID: "2", PrivilegeID: "64e60d28eac51324f2296753", Name: "100 генераций", ServiceKey: "test", Description: "This is a test 100 генераций", Type: "count", Price: 1000, Value: "100", Amount: 5, IsDeleted: false, CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: time.Time{}, }, }, } fiberClient := fiber.Client{} controller := NewPrivilege(client, &fiberClient) privileges, err := controller.getActualPrivileges() err = controller.updatePrivileges(privileges) assert.Nil(t, err) } func TestSetupActualPrivileges(t *testing.T) { client := Client{ URL: "http://localhost:8001", ServiceName: "key", Privileges: []Privilege{ { Name: "TestSetupActualPrivileges", PrivilegeID: "test1", ServiceKey: "key", Description: "This is a test", Type: "count", Value: "100", Price: 10.0, Amount: 5, IsDeleted: false, CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: time.Time{}, }, }, } fiberClient := fiber.Client{} controller := NewPrivilege(client, &fiberClient) err := controller.setupActualPrivileges() assert.Nil(t, err, "error") } func TestRemovePrivilege(t *testing.T) { client := Client{ URL: "http://localhost:8001", ServiceName: "key", Privileges: []Privilege{ { ID: "2", PrivilegeID: "64e60d28eac51324f2296753", Name: "100 генераций", ServiceKey: "test", Description: "This is a test 100 генераций", Type: "count", Value: "100", Amount: 5, IsDeleted: false, CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: time.Time{}, }, }, } fiberClient := fiber.Client{} controller := NewPrivilege(client, &fiberClient) err := controller.removePrivilege("64e60d28eac51324f2296753") assert.Nil(t, err) }