Skip to content

Commit 345cc0f

Browse files
committed
test: add community v2 endpoint coverage
1 parent 2675729 commit 345cc0f

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

doc/v2.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ This is a comprehensive guide of all methods available for the Twitter API v2 on
9191
- [Search spaces](#search-spaces)
9292
- [Space buyers](#space-buyers)
9393
- [Space tweets](#space-tweets)
94+
- [Communities](#communities)
95+
- [Community by id](#community-by-id)
96+
- [Search communities](#search-communities)
9497
- [Direct messages (DMs)](#direct-messages-dms)
9598
- [Fetch direct message events (without filter)](#fetch-direct-message-events-without-filter)
9699
- [Fetch direct message events by participant id](#fetch-direct-message-events-by-participant-id)
@@ -1534,6 +1537,34 @@ const { data: tweets } = await client.v2.spaceTweets('space-id')
15341537
// tweets is a TweetV2[]
15351538
```
15361539

1540+
## Communities
1541+
1542+
### Community by id
1543+
1544+
Retrieve details of a specific community.
1545+
1546+
**Method**: `.community(communityId, options?)`
1547+
1548+
**Endpoint**: `communities/:id`
1549+
1550+
**Right level**: `Read`
1551+
1552+
**Returns**: `CommunityV2Result`
1553+
1554+
### Search communities
1555+
1556+
Search for communities that match a given query.
1557+
1558+
**Method**: `.searchCommunities(query, options?)`
1559+
1560+
**Endpoint**: `communities/search`
1561+
1562+
**Right level**: `Read`
1563+
1564+
**Returns**: `CommunitiesV2Result`
1565+
1566+
The community object includes fields such as `description`, `private`, `member_count`, `moderator_count`, `subscriber_count`, `creator_id` and `rules`.
1567+
15371568
## Direct messages (DMs)
15381569

15391570
### Fetch direct message events (without filter)

src/types/v2/community.v2.types.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1+
export interface CommunityRuleV2 {
2+
/** Identifier of the rule. */
3+
id: string;
4+
/** Text of the rule. */
5+
text: string;
6+
/** Creation date of the rule. */
7+
created_at?: string;
8+
}
9+
110
export interface CommunityV2 {
211
id: string;
312
name: string;
13+
/** Description of the community. */
14+
description?: string;
15+
/** Identifier of the community creator. */
16+
creator_id?: string;
417
created_at: string;
18+
/** Indicates if the community is private. */
19+
private?: boolean;
20+
/** Number of members in the community. */
21+
member_count?: number;
22+
/** Number of moderators in the community. */
23+
moderator_count?: number;
24+
/** Number of subscribers of the community. */
25+
subscriber_count?: number;
26+
/** Rules that apply to the community. */
27+
rules?: CommunityRuleV2[];
528
}
629

730
export interface CommunityErrorV2 {

test/community.v2.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import 'mocha';
2+
import { expect } from 'chai';
3+
import { TwitterApi } from '../src';
4+
import { getAppClient } from '../src/test/utils';
5+
6+
let client: TwitterApi;
7+
8+
describe.skip('Community endpoints for v2 API', () => {
9+
before(async () => {
10+
client = await getAppClient();
11+
});
12+
13+
it('.community - Lookup community details', async () => {
14+
const community = await client.v2.community('1');
15+
16+
expect(community.data.id).to.be.a('string');
17+
expect(community.data.name).to.be.a('string');
18+
// Newly documented fields
19+
expect(community.data.description).to.be.a('string');
20+
expect(community.data.private).to.be.a('boolean');
21+
expect(community.data.member_count).to.be.a('number');
22+
}).timeout(60 * 1000);
23+
});

0 commit comments

Comments
 (0)