Skip to content

Commit

Permalink
chore: update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeodor committed Jun 6, 2024
1 parent 5599f57 commit 476e82d
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 94 deletions.
17 changes: 7 additions & 10 deletions cli/cmd/organization/list/organization_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ func TestList(t *testing.T) {
Slug: fmt.Sprintf("name-%s-slug", id),
},
}
organizationsAsStrings = append(organizationsAsStrings, test.OrganizationMembershipToResponse(struct {
Role test.Role
Organization struct {
ID string
Name string
Slug string
}
}{
Role: test.Role(organization.Role),
Organization: organization.Organization,
organizationsAsStrings = append(organizationsAsStrings, test.OrganizationMembershipToResponse(test.Membership{
Role: test.Role(organization.Role),
Organization: test.Organization{
ID: organization.Organization.ID,
Name: organization.Organization.Name,
Slug: organization.Organization.Slug,
},
}))
}

Expand Down
14 changes: 11 additions & 3 deletions cli/internal/gql/organization/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package organization

import (
"context"
"errors"

"git.sr.ht/~emersion/gqlclient"
)
Expand All @@ -22,16 +23,23 @@ func Create(name string, client *gqlclient.Client) (Organization, error) {
return resp.OrganizationCreate, err
}

if resp.OrganizationCreate.Typename != "Organization" {
return resp.OrganizationCreate, errors.New(resp.OrganizationCreate.Typename)
}

return resp.OrganizationCreate, nil
}

func createOrganizationCreateOperation(name string) *gqlclient.Operation {
op := gqlclient.NewOperation(`
mutation OrganizationCreate($name: String!) {
organizationCreate(input: { name: $name }) {
id
name
slug
__typename
... on Organization {
id
name
slug
}
}
}
`)
Expand Down
22 changes: 18 additions & 4 deletions cli/internal/gql/organization/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
func TestCreate(t *testing.T) {
t.Run("can return organization on OrganizationCreate mutation", func(t *testing.T) {
expectedOrganization := Organization{
ID: "id",
Name: "name",
Slug: "slug",
Typename: "Organization",
ID: "id",
Name: "name",
Slug: "slug",
}
response := organizationToQueryResult("organizationCreate", expectedOrganization)
c := test.CreateTestGqlClient(t, response)
Expand Down Expand Up @@ -46,6 +47,18 @@ func TestCreate(t *testing.T) {
assert.NotErrorIs(t, err, ErrOrganizationNameInvalidCharacter)
assert.Equal(t, Organization{}, actualOrganization)
})

t.Run("given non-organization return type it returns the type as an error", func(t *testing.T) {
o := Organization{Typename: "OrganizationSlugOccupied"}
response := organizationToQueryResult("organizationCreate", o)
c := test.CreateTestGqlClient(t, response)

_, err := Create("", c)

if assert.Error(t, err) {
assert.Equal(t, "OrganizationSlugOccupied", err.Error())
}
})
}

func organizationToQueryResult(queryName string, o Organization) string {
Expand All @@ -58,8 +71,9 @@ func organizationToQueryResult(queryName string, o Organization) string {

func organizationToResponse(o Organization) string {
return fmt.Sprintf(`{
"__typename": "%s",
"id": "%s",
"name": "%s",
"slug": "%s"
}`, o.ID, o.Name, o.Slug)
}`, o.Typename, o.ID, o.Name, o.Slug)
}
7 changes: 4 additions & 3 deletions cli/internal/gql/organization/types.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package organization

type Organization struct {
ID string
Name string
Slug string
Typename string `json:"__typename"`
ID string
Name string
Slug string
}

type Role string
Expand Down
17 changes: 7 additions & 10 deletions cli/internal/gql/user/query_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ func TestQueryUser(t *testing.T) {
FullName: "Test User",
Memberships: []organization.OrganizationMembership{membership},
}
membershipAsString := test.OrganizationMembershipToResponse(struct {
Role test.Role
Organization struct {
ID string
Name string
Slug string
}
}{
Role: test.Role(membership.Role),
Organization: membership.Organization,
membershipAsString := test.OrganizationMembershipToResponse(test.Membership{
Role: test.Role(membership.Role),
Organization: test.Organization{
ID: membership.Organization.ID,
Name: membership.Organization.Name,
Slug: membership.Organization.Slug,
},
})

response := `{
Expand Down
19 changes: 11 additions & 8 deletions cli/test/query_response_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ const (
User Role = "USER"
)

func OrganizationMembershipToResponse(o struct {
type Organization struct {
ID string
Name string
Slug string
}

type Membership struct {
Role Role
Organization struct {
ID string
Name string
Slug string
}
},
) string {
Organization Organization
}

func OrganizationMembershipToResponse(o Membership) string {
return fmt.Sprintf(`{
"role": "%s",
"organization": {
Expand Down
10 changes: 6 additions & 4 deletions python/src/numerous/generated/graphql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
AppSubscriptionStatus,
AuthRole,
Role,
ShareOfferStatus,
SubscriptionOfferStatus,
ToolHashType,
)
from .exceptions import (
Expand All @@ -47,6 +47,7 @@
)
from .input_types import (
AppCreateInfo,
AppDeployInput,
AppSecret,
BuildPushInput,
ElementInput,
Expand All @@ -55,7 +56,7 @@
NewOrganization,
NewTool,
OrganizationInvitationInput,
ShareOfferInput,
SubscriptionOfferInput,
)
from .update_element import UpdateElement, UpdateElementElementUpdate
from .updates import (
Expand Down Expand Up @@ -95,6 +96,7 @@
"AllElementsSessionAllTextField",
"AllElementsSessionAllTextFieldGraphContext",
"AppCreateInfo",
"AppDeployInput",
"AppDeploymentStatus",
"AppSecret",
"AppSubscriptionStatus",
Expand Down Expand Up @@ -122,9 +124,9 @@
"NumberFieldValue",
"OrganizationInvitationInput",
"Role",
"ShareOfferInput",
"ShareOfferStatus",
"SliderValue",
"SubscriptionOfferInput",
"SubscriptionOfferStatus",
"TextFieldValue",
"ToolHashType",
"UpdateElement",
Expand Down
2 changes: 1 addition & 1 deletion python/src/numerous/generated/graphql/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AppDeploymentStatus(str, Enum):
UNKNOWN = "UNKNOWN"


class ShareOfferStatus(str, Enum):
class SubscriptionOfferStatus(str, Enum):
ACCEPTED = "ACCEPTED"
REJECTED = "REJECTED"
PENDING = "PENDING"
Expand Down
17 changes: 11 additions & 6 deletions python/src/numerous/generated/graphql/input_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
from .enums import Role


class NewOrganization(BaseModel):
name: str
slug: Optional[str] = None


class OrganizationInvitationInput(BaseModel):
role: Role
email: str


class NewOrganization(BaseModel):
name: str


class NewTool(BaseModel):
user_id: str = Field(alias="userId")
manifest: str
Expand All @@ -29,9 +30,13 @@ class AppCreateInfo(BaseModel):
description: str


class ShareOfferInput(BaseModel):
class AppDeployInput(BaseModel):
secrets: Optional[List["AppSecret"]] = None


class SubscriptionOfferInput(BaseModel):
email: str
app_id: str = Field(alias="appId")
app_name: str = Field(alias="appName")


class ElementInput(BaseModel):
Expand Down
Loading

0 comments on commit 476e82d

Please sign in to comment.