Skip to content

Commit

Permalink
Add test cases for JSON resource marshaling (#1929)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagar23sj authored Jul 8, 2021
1 parent 908fe35 commit 0491dfa
Showing 1 changed file with 182 additions and 0 deletions.
182 changes: 182 additions & 0 deletions github/authorizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,185 @@ func TestAuthorizationsService_DeleteImpersonation(t *testing.T) {
return client.Authorizations.DeleteImpersonation(ctx, "u")
})
}

func TestAuthorizationUpdateRequest_Marshal(t *testing.T) {
testJSONMarshal(t, &AuthorizationUpdateRequest{}, "{}")

u := &AuthorizationUpdateRequest{
Scopes: []string{"s"},
AddScopes: []string{"a"},
RemoveScopes: []string{"r"},
Note: String("n"),
NoteURL: String("nu"),
Fingerprint: String("f"),
}

want := `{
"scopes": ["s"],
"add_scopes": ["a"],
"remove_scopes": ["r"],
"note": "n",
"note_url": "nu",
"fingerprint": "f"
}`

testJSONMarshal(t, u, want)
}

func TestAuthorizationRequest_Marshal(t *testing.T) {
testJSONMarshal(t, &AuthorizationRequest{}, "{}")

u := &AuthorizationRequest{
Scopes: []Scope{"s"},
ClientID: String("cid"),
ClientSecret: String("cs"),
Note: String("n"),
NoteURL: String("nu"),
Fingerprint: String("f"),
}

want := `{
"scopes": ["s"],
"client_id": "cid",
"client_secret": "cs",
"note": "n",
"note_url": "nu",
"fingerprint": "f"
}`

testJSONMarshal(t, u, want)
}

func TestAuthorizationApp_Marshal(t *testing.T) {
testJSONMarshal(t, &AuthorizationApp{}, "{}")

u := &AuthorizationApp{
URL: String("u"),
Name: String("n"),
ClientID: String("cid"),
}

want := `{
"url": "u",
"name": "n",
"client_id": "cid"
}`

testJSONMarshal(t, u, want)
}

func TestGrant_Marshal(t *testing.T) {
testJSONMarshal(t, &Grant{}, "{}")

u := &Grant{
ID: Int64(1),
URL: String("u"),
App: &AuthorizationApp{
URL: String("u"),
Name: String("n"),
ClientID: String("cid"),
},
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
Scopes: []string{"s"},
}

want := `{
"id": 1,
"url": "u",
"app": {
"url": "u",
"name": "n",
"client_id": "cid"
},
"created_at": ` + referenceTimeStr + `,
"updated_at": ` + referenceTimeStr + `,
"scopes": ["s"]
}`

testJSONMarshal(t, u, want)
}

func TestAuthorization_Marshal(t *testing.T) {
testJSONMarshal(t, &Authorization{}, "{}")

u := &Authorization{
ID: Int64(1),
URL: String("u"),
Scopes: []Scope{"s"},
Token: String("t"),
TokenLastEight: String("tle"),
HashedToken: String("ht"),
App: &AuthorizationApp{
URL: String("u"),
Name: String("n"),
ClientID: String("cid"),
},
Note: String("n"),
NoteURL: String("nu"),
UpdatedAt: &Timestamp{referenceTime},
CreatedAt: &Timestamp{referenceTime},
Fingerprint: String("f"),
User: &User{
Login: String("l"),
ID: Int64(1),
URL: String("u"),
AvatarURL: String("a"),
GravatarID: String("g"),
Name: String("n"),
Company: String("c"),
Blog: String("b"),
Location: String("l"),
Email: String("e"),
Hireable: Bool(true),
Bio: String("b"),
TwitterUsername: String("t"),
PublicRepos: Int(1),
Followers: Int(1),
Following: Int(1),
CreatedAt: &Timestamp{referenceTime},
SuspendedAt: &Timestamp{referenceTime},
},
}

want := `{
"id": 1,
"url": "u",
"scopes": ["s"],
"token": "t",
"token_last_eight": "tle",
"hashed_token": "ht",
"app": {
"url": "u",
"name": "n",
"client_id": "cid"
},
"note": "n",
"note_url": "nu",
"updated_at": ` + referenceTimeStr + `,
"created_at": ` + referenceTimeStr + `,
"fingerprint": "f",
"user": {
"login": "l",
"id": 1,
"avatar_url": "a",
"gravatar_id": "g",
"name": "n",
"company": "c",
"blog": "b",
"location": "l",
"email": "e",
"hireable": true,
"bio": "b",
"twitter_username": "t",
"public_repos": 1,
"followers": 1,
"following": 1,
"created_at": ` + referenceTimeStr + `,
"suspended_at": ` + referenceTimeStr + `,
"url": "u"
}
}`

testJSONMarshal(t, u, want)
}

0 comments on commit 0491dfa

Please sign in to comment.