Skip to content

Commit

Permalink
feat: fixed for the issue (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: myConsciousness <contact@shinyakato.dev>”
  • Loading branch information
myConsciousness committed Dec 30, 2022
1 parent 31e514e commit 9a076be
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/src/service/v1/accounts/accounts_v1_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,32 @@ abstract class AccountsV1Service {
List<String>? statusIds,
List<String>? ruleIds,
});

/// Accounts that the user is currently featuring on their profile.
///
/// ## Parameters
///
/// - [limit]: Maximum number of results to return. Defaults to 40 accounts.
/// Max 80 accounts.
///
/// ## Endpoint Url
///
/// - GET /api/v1/endorsements HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - read:accounts
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/endorsements/#get
Future<MastodonResponse<List<Account>>> lookupFeaturedProfiles({
int? limit,
});
}

class _AccountsV1Service extends BaseService implements AccountsV1Service {
Expand Down Expand Up @@ -1637,4 +1663,19 @@ class _AccountsV1Service extends BaseService implements AccountsV1Service {
),
dataBuilder: Report.fromJson,
);

@override
Future<MastodonResponse<List<Account>>> lookupFeaturedProfiles({
int? limit,
}) async =>
super.transformMultiDataResponse(
await super.get(
UserContext.oauth2Only,
'/api/v1/endorsements',
queryParameters: {
'limit': limit,
},
),
dataBuilder: Account.fromJson,
);
}
69 changes: 69 additions & 0 deletions test/src/service/v1/accounts/accounts_v1_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2219,4 +2219,73 @@ void main() {
);
});
});

group('.lookupFeaturedProfiles', () {
test('normal case', () async {
final accountsService = AccountsV1Service(
instance: 'test',
context: context.buildGetStub(
'test',
UserContext.oauth2Only,
'/api/v1/endorsements',
'test/src/service/v1/accounts/data/lookup_featured_profiles.json',
{
'limit': '40',
},
),
);

final response = await accountsService.lookupFeaturedProfiles(
limit: 40,
);

expect(response, isA<MastodonResponse>());
expect(response.rateLimit, isA<RateLimit>());
expect(response.data, isA<List<Account>>());
});

test('when unauthorized', () async {
final accountsService = AccountsV1Service(
instance: 'test',
context: context.buildGetStub(
'test',
UserContext.oauth2Only,
'/api/v1/endorsements',
'test/src/service/v1/accounts/data/lookup_featured_profiles.json',
{
'limit': '40',
},
statusCode: 401,
),
);

expectUnauthorizedException(
() async => await accountsService.lookupFeaturedProfiles(
limit: 40,
),
);
});

test('when rate limit exceeded', () async {
final accountsService = AccountsV1Service(
instance: 'test',
context: context.buildGetStub(
'test',
UserContext.oauth2Only,
'/api/v1/endorsements',
'test/src/service/v1/accounts/data/lookup_featured_profiles.json',
{
'limit': '40',
},
statusCode: 429,
),
);

expectRateLimitExceededException(
() async => await accountsService.lookupFeaturedProfiles(
limit: 40,
),
);
});
});
}
51 changes: 51 additions & 0 deletions test/src/service/v1/accounts/data/lookup_featured_profiles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"id": "952529",
"username": "alayna",
"acct": "alayna@desvox.es",
"display_name": "Alayna Desirae",
"locked": true,
"bot": false,
"created_at": "2019-10-26T23:12:06.570Z",
"note": "experiencing ________ difficulties<br>22y/o INFP in Oklahoma",
"url": "https://desvox.es/users/alayna",
"avatar": "https://files.mastodon.social/accounts/avatars/000/952/529/original/6534122046d050d5.png",
"avatar_static": "https://files.mastodon.social/accounts/avatars/000/952/529/original/6534122046d050d5.png",
"header": "https://files.mastodon.social/accounts/headers/000/952/529/original/496f1f817e042ade.png",
"header_static": "https://files.mastodon.social/accounts/headers/000/952/529/original/496f1f817e042ade.png",
"followers_count": 0,
"following_count": 0,
"statuses_count": 955,
"last_status_at": "2019-11-23T07:05:50.682Z",
"emojis": [],
"fields": []
},
{
"id": "832844",
"username": "a9",
"acct": "a9@broadcast.wolfgirl.engineering",
"display_name": "vivienne :collar: ",
"locked": true,
"bot": false,
"created_at": "2019-06-12T18:55:12.053Z",
"note": "borderline nsfw, considered a schedule I drug by nixon<br>waiting for the year of the illumos desktop",
"url": "https://broadcast.wolfgirl.engineering/users/a9",
"avatar": "https://files.mastodon.social/accounts/avatars/000/832/844/original/ae1de0b8fb63d1c6.png",
"avatar_static": "https://files.mastodon.social/accounts/avatars/000/832/844/original/ae1de0b8fb63d1c6.png",
"header": "https://files.mastodon.social/accounts/headers/000/832/844/original/5088e4a16e6d8736.png",
"header_static": "https://files.mastodon.social/accounts/headers/000/832/844/original/5088e4a16e6d8736.png",
"followers_count": 43,
"following_count": 67,
"statuses_count": 5906,
"last_status_at": "2019-11-23T05:23:47.911Z",
"emojis": [
{
"shortcode": "collar",
"url": "https://files.mastodon.social/custom_emojis/images/000/106/920/original/80953b9cd96ec4dc.png",
"static_url": "https://files.mastodon.social/custom_emojis/images/000/106/920/static/80953b9cd96ec4dc.png",
"visible_in_picker": true
}
],
"fields": []
}
]

0 comments on commit 9a076be

Please sign in to comment.