Skip to content

Commit b69c6f3

Browse files
committed
test TwitterTweetFieldsV2
1 parent 9c3cc26 commit b69c6f3

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

Sources/TwitterAPIKit/APIv2/FieldsV2.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public enum TwitterTweetFieldsV2: TwitterAPIv2RequestParameter, Hashable {
2525
case source
2626
case text
2727
case withheld
28+
case other(String)
2829

2930
public var stringValue: String {
3031

@@ -69,6 +70,8 @@ public enum TwitterTweetFieldsV2: TwitterAPIv2RequestParameter, Hashable {
6970
return "text"
7071
case .withheld:
7172
return "withheld"
73+
case .other(let other):
74+
return other
7275
}
7376
}
7477
}

Sources/TwitterAPIKit/APIv2/TwitterAPIv2.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public protocol TwitterAPIv2RequestParameter {
5454
var stringValue: String { get }
5555
}
5656

57-
extension Set where Element: TwitterAPIv2RequestParameter {
57+
extension Collection where Element: TwitterAPIv2RequestParameter {
5858
var commaSeparatedString: String {
5959
return map { $0.stringValue }.sorted().joined(separator: ",")
6060
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import XCTest
2+
3+
@testable import TwitterAPIKit
4+
5+
class FieldsV2Tests: XCTestCase {
6+
7+
// https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/tweet
8+
// [...$0.rows].slice(1).map(tr => { return tr.cells[0].textContent.replace("(default)", "").trim()}).sort().join(",")
9+
10+
override func setUpWithError() throws {
11+
}
12+
13+
override func tearDownWithError() throws {
14+
}
15+
16+
func testTwitterTweetFieldsV2() throws {
17+
18+
let allCases: [TwitterTweetFieldsV2] = [
19+
.attachments,
20+
.authorID,
21+
.contextAnnotations,
22+
.conversationID,
23+
.createdAt,
24+
.entities,
25+
.geo,
26+
.id,
27+
.inReplyToUserID,
28+
.lang,
29+
.nonPublicMetrics,
30+
.publicMetrics,
31+
.organicMetrics,
32+
.promotedMetrics,
33+
.possiblySensitive,
34+
.referencedTweets,
35+
.replySettings,
36+
.source,
37+
.text,
38+
.withheld,
39+
.other("~~~"),
40+
]
41+
42+
XCTAssertEqual(
43+
allCases.commaSeparatedString,
44+
"attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,non_public_metrics,organic_metrics,possibly_sensitive,promoted_metrics,public_metrics,referenced_tweets,reply_settings,source,text,withheld,~~~"
45+
)
46+
}
47+
}

0 commit comments

Comments
 (0)