-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#65 admin/promo/create #103
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package promo | ||
|
||
import ( | ||
"github.com/yitsushi/go-misskey/core" | ||
) | ||
|
||
// CreateRequest is the request object for a Create request. | ||
type CreateRequest struct { | ||
NoteID string `json:"noteId"` // required: <misskey:id> | ||
ExpiresAt int64 `json:"expiresAt"` // required: time.Now().Add(0,86400000,0).Unix() | ||
} | ||
|
||
// Validate the request. | ||
func (r CreateRequest) Validate() error { | ||
if r.NoteID == "" { | ||
return core.RequestValidationError{ | ||
Request: r, | ||
Message: core.UndefinedRequiredField, | ||
Field: "noteId", | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Create is the endpoint to create a promo. | ||
func (s *Service) Create(request CreateRequest) error { | ||
err := s.Call( | ||
&core.JSONRequest{ | ||
Request: &request, | ||
Path: "/admin/promo/create", | ||
}, | ||
&core.EmptyResponse{}, | ||
) | ||
|
||
return err | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package promo_test | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/yitsushi/go-misskey" | ||
"github.com/yitsushi/go-misskey/core" | ||
"github.com/yitsushi/go-misskey/services/admin/promo" | ||
"github.com/yitsushi/go-misskey/test" | ||
) | ||
|
||
func TestService_Create(t *testing.T) { | ||
client := test.MakeMockClient(test.SimpleMockOptions{ | ||
Endpoint: "/api/admin/promo/create", | ||
RequestData: &promo.CreateRequest{}, | ||
ResponseFile: "create.json", | ||
StatusCode: http.StatusOK, | ||
}) | ||
|
||
err := client.Admin().Promo().Create(promo.CreateRequest{ | ||
NoteID: "noteID", | ||
ExpiresAt: time.Now().Add(86400 * 24 * time.Hour).Unix(), | ||
}) | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
} | ||
|
||
func TestService_Create_Error(t *testing.T) { | ||
client := test.MakeMockClient(test.SimpleMockOptions{ | ||
Endpoint: "/api/admin/promo/create", | ||
RequestData: &promo.CreateRequest{}, | ||
ResponseFile: "create.json", | ||
StatusCode: http.StatusOK, | ||
}) | ||
|
||
// success | ||
err := client.Admin().Promo().Create(promo.CreateRequest{ | ||
NoteID: "noteID", | ||
ExpiresAt: time.Now().Add(86400 * 24 * time.Hour).Unix(), | ||
}) | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
} | ||
|
||
func TestPromoRequest_Validate(t *testing.T) { | ||
test.ValidateRequests( | ||
t, | ||
[]core.BaseRequest{ | ||
promo.CreateRequest{}, | ||
}, | ||
[]core.BaseRequest{ | ||
promo.CreateRequest{NoteID: "8zwxx3cpy7", ExpiresAt: 0}, | ||
promo.CreateRequest{NoteID: "8zwxx3cpy8", ExpiresAt: 0}, | ||
promo.CreateRequest{NoteID: "8zwxx3cpy9", ExpiresAt: time.Now().Add(86400 * 24 * time.Hour).Unix()}, | ||
}, | ||
) | ||
} | ||
|
||
func ExampleService_CreatePromo() { | ||
Check failure on line 66 in services/admin/promo/create_test.go GitHub Actions / go vet and lint
|
||
yitsushi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) | ||
|
||
err := client.Admin().Promo().Create(promo.CreateRequest{ | ||
NoteID: "8dsk7x47y3", | ||
ExpiresAt: time.Now().Add(24 * time.Hour).Unix(), | ||
}) | ||
if err != nil { | ||
log.Printf("[Admin/Promo/Create] %s", err) | ||
|
||
return | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package promo | ||
|
||
import ( | ||
"github.com/yitsushi/go-misskey/core" | ||
) | ||
|
||
// Service is the base for all the endpoints on this service. | ||
type Service struct { | ||
Call core.RequestHandlerFunc | ||
} | ||
|
||
// NewService creates a new Service instance. | ||
func NewService(requestHandler core.RequestHandlerFunc) *Service { | ||
return &Service{Call: requestHandler} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add an example in the test, like other endpoints has? That way we always have simple examples for all endpoints that can be copy pasted if someone wants to play around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have added an example of creating a promo request, following the example.