Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #90 from mironal/test-fav-v1
Browse files Browse the repository at this point in the history
Test fav v1
  • Loading branch information
mironal committed Mar 12, 2022
2 parents 9fa373c + 8d26759 commit 5135b52
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import TwitterAPIKit
import XCTest

class GetFavoritesRequestV1Tests: XCTestCase {
override func setUpWithError() throws {
}

override func tearDownWithError() throws {
}

func test() throws {
let req = GetFavoritesRequestV1(
target: .userID("uid"),
count: 100,
sinceID: "_s_",
maxID: "_m_",
includeEntities: true
)

XCTAssertEqual(req.method, .get)
XCTAssertEqual(req.baseURLType, .api)
XCTAssertEqual(req.path, "/1.1/favorites/list.json")
XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded)
AssertEqualAnyDict(
req.parameters,
[
"user_id": "uid",
"count": 100,
"since_id": "_s_",
"max_id": "_m_",
"include_entities": true,
]
)
}

func testDefaultArg() throws {
let req = GetFavoritesRequestV1(
target: .screenName("s")
)

AssertEqualAnyDict(
req.parameters,
[
"screen_name": "s"
]
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import TwitterAPIKit
import XCTest

class PostFavoriteRequestV1Tests: XCTestCase {
override func setUpWithError() throws {
}

override func tearDownWithError() throws {
}

func test() throws {
let req = PostFavoriteRequestV1(
id: "_i_",
includeEntities: true
)

XCTAssertEqual(req.method, .post)
XCTAssertEqual(req.baseURLType, .api)
XCTAssertEqual(req.path, "/1.1/favorites/create.json")
XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded)
AssertEqualAnyDict(
req.parameters,
[
"id": "_i_",
"include_entities": true,
]
)
}

func testDefaultArg() throws {
let req = PostFavoriteRequestV1(
id: "_i_"
)

AssertEqualAnyDict(
req.parameters,
[
"id": "_i_"
]
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import TwitterAPIKit
import XCTest

class PostUnFavoriteRequestV1Tests: XCTestCase {
override func setUpWithError() throws {
}

override func tearDownWithError() throws {
}

func test() throws {
let req = PostUnFavoriteRequestV1(
id: "_i_",
includeEntities: true
)

XCTAssertEqual(req.method, .post)
XCTAssertEqual(req.baseURLType, .api)
XCTAssertEqual(req.path, "/1.1/favorites/destroy.json")
XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded)
AssertEqualAnyDict(
req.parameters,
[
"id": "_i_",
"include_entities": true,
]
)
}

func testDefaultArg() throws {
let req = PostUnFavoriteRequestV1(
id: "_i_"
)

AssertEqualAnyDict(
req.parameters,
[
"id": "_i_"
]
)
}
}
6 changes: 6 additions & 0 deletions test-template.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and edit generated test code.
{{param.name}}: "_{{param.name[0]}}_"{{ ',' if not forloop.last }}
{% elif param.typeName.unwrappedTypeName == "Int" %}
{{param.name}}: 1{{ ',' if not forloop.last }}
{% elif param.typeName.unwrappedTypeName == "Bool" %}
{{param.name}}: true{{ ',' if not forloop.last }}
{% elif param.typeName.unwrappedTypeName == "Date" %}
{{param.name}}: Date(timeIntervalSince1970: 0){{ ',' if not forloop.last }}
{% elif param.type.kind == "enum" %}
Expand All @@ -22,6 +24,10 @@ and edit generated test code.
{% endif %}
{% elif param.typeName.unwrappedTypeName|hasPrefix: "Set<" %}
{{param.name}}: []{{ ',' if not forloop.last }}
{% elif param.typeName.unwrappedTypeName|hasPrefix: "TwitterUserIdentifierV1" %}
{{param.name}}: .userID("uid"){{ ',' if not forloop.last }}
{% elif param.typeName.unwrappedTypeName|hasPrefix: "TwitterUsersIdentifierV1" %}
{{param.name}}: userIDs["uid1", "uid2"]{{ ',' if not forloop.last }}
{% elif param.typeName.isOptional %}
{{param.name}}: {{param.defaultValue}}{{ ',' if not forloop.last }}
{% else %}
Expand Down

0 comments on commit 5135b52

Please sign in to comment.