forked from dart-lang/pub-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move admin action tests to separate files. (dart-lang#8002)
- Loading branch information
Showing
4 changed files
with
103 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,8 @@ | |
|
||
import 'package:_pub_shared/data/admin_api.dart'; | ||
import 'package:clock/clock.dart'; | ||
import 'package:pub_dev/account/backend.dart'; | ||
import 'package:pub_dev/package/backend.dart'; | ||
import 'package:pub_dev/package/models.dart'; | ||
import 'package:pub_dev/publisher/backend.dart'; | ||
import 'package:pub_dev/shared/datastore.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
|
@@ -41,74 +39,6 @@ void main() { | |
}); | ||
}); | ||
|
||
testWithProfile( | ||
'creating, listing members and deleting publisher with no packages', | ||
fn: () async { | ||
final client = createPubApiClient(authToken: siteAdminToken); | ||
final p0 = await publisherBackend.getPublisher('other.com'); | ||
expect(p0, isNull); | ||
final rs1 = await client.adminInvokeAction( | ||
'publisher-create', | ||
AdminInvokeActionArguments(arguments: { | ||
'publisher': 'other.com', | ||
'member-email': '[email protected]', | ||
}), | ||
); | ||
expect(rs1.output, { | ||
'message': 'Publisher created.', | ||
'publisherId': 'other.com', | ||
'member-email': '[email protected]', | ||
}); | ||
final publisherMembersResponse = await client.adminInvokeAction( | ||
'publisher-members-list', | ||
AdminInvokeActionArguments(arguments: { | ||
'publisher': 'other.com', | ||
}), | ||
); | ||
expect(publisherMembersResponse.output, { | ||
'publisher': 'other.com', | ||
'description': '', | ||
'website': 'https://other.com/', | ||
'contact': '[email protected]', | ||
'created': isA<String>(), | ||
'members': [ | ||
{'email': '[email protected]', 'role': 'admin', 'userId': isA<String>()} | ||
] | ||
}); | ||
final p1 = await publisherBackend.getPublisher('other.com'); | ||
expect(p1, isNotNull); | ||
final rs2 = await client.adminInvokeAction('publisher-delete', | ||
AdminInvokeActionArguments(arguments: {'publisher': 'other.com'})); | ||
expect(rs2.output, { | ||
'message': 'Publisher and all members deleted.', | ||
'publisherId': 'other.com', | ||
'members-count': 1, | ||
}); | ||
final p2 = await publisherBackend.getPublisher('other.com'); | ||
expect(p2, isNull); | ||
}); | ||
|
||
testWithProfile('remove package from publisher', fn: () async { | ||
final api = createPubApiClient(authToken: siteAdminToken); | ||
final result = await api.adminInvokeAction( | ||
'publisher-package-remove', | ||
AdminInvokeActionArguments(arguments: {'package': 'neon'}), | ||
); | ||
final neon = await packageBackend.lookupPackage('neon'); | ||
|
||
expect(result.output, { | ||
'previousPublisher': 'example.com', | ||
'package': 'neon', | ||
'uploaders': [ | ||
{'email': '[email protected]', 'userId': neon!.uploaders!.first} | ||
] | ||
}); | ||
final packagePublisherInfo = await packageBackend.getPublisherInfo('neon'); | ||
expect(packagePublisherInfo.publisherId, isNull); | ||
final emails = await accountBackend.getEmailsOfUserIds(neon.uploaders!); | ||
expect(emails, {'[email protected]'}); | ||
}); | ||
|
||
testWithProfile('user-info', fn: () async { | ||
final api = createPubApiClient(authToken: siteAdminToken); | ||
final result = await api.adminInvokeAction( | ||
|
@@ -179,34 +109,4 @@ void main() { | |
.uploadPackageBytes(bytes); | ||
expect(rs2.success.message, contains('Successfully uploaded')); | ||
}); | ||
|
||
testWithProfile('package-version-retraction', fn: () async { | ||
final latest = await packageBackend.getLatestVersion('oxygen'); | ||
|
||
final api = createPubApiClient(authToken: siteAdminToken); | ||
final result = await api.adminInvokeAction( | ||
'package-version-retraction', | ||
AdminInvokeActionArguments(arguments: { | ||
'package': 'oxygen', | ||
'version': latest!, | ||
'set-retracted': 'true', | ||
}), | ||
); | ||
|
||
expect(result.output, { | ||
'before': { | ||
'package': 'oxygen', | ||
'version': latest, | ||
'isRetracted': false, | ||
}, | ||
'after': { | ||
'package': 'oxygen', | ||
'version': latest, | ||
'isRetracted': true, | ||
}, | ||
}); | ||
|
||
final newLatest = await packageBackend.getLatestVersion('oxygen'); | ||
expect(newLatest != latest, isTrue); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,15 @@ | |
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:_pub_shared/data/admin_api.dart'; | ||
import 'package:pub_dev/account/backend.dart'; | ||
import 'package:pub_dev/package/backend.dart'; | ||
import 'package:pub_dev/publisher/backend.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../shared/test_models.dart'; | ||
import '../shared/test_services.dart'; | ||
|
||
void main() { | ||
// TODO: move publisher-related tests from api_actions_test.dart | ||
group('publisher admin actions', () { | ||
testWithProfile('info request', fn: () async { | ||
final client = createPubApiClient(authToken: siteAdminToken); | ||
|
@@ -28,5 +30,74 @@ void main() { | |
}, | ||
}); | ||
}); | ||
|
||
testWithProfile( | ||
'creating, listing members and deleting publisher with no packages', | ||
fn: () async { | ||
final client = createPubApiClient(authToken: siteAdminToken); | ||
final p0 = await publisherBackend.getPublisher('other.com'); | ||
expect(p0, isNull); | ||
final rs1 = await client.adminInvokeAction( | ||
'publisher-create', | ||
AdminInvokeActionArguments(arguments: { | ||
'publisher': 'other.com', | ||
'member-email': '[email protected]', | ||
}), | ||
); | ||
expect(rs1.output, { | ||
'message': 'Publisher created.', | ||
'publisherId': 'other.com', | ||
'member-email': '[email protected]', | ||
}); | ||
final publisherMembersResponse = await client.adminInvokeAction( | ||
'publisher-members-list', | ||
AdminInvokeActionArguments(arguments: { | ||
'publisher': 'other.com', | ||
}), | ||
); | ||
expect(publisherMembersResponse.output, { | ||
'publisher': 'other.com', | ||
'description': '', | ||
'website': 'https://other.com/', | ||
'contact': '[email protected]', | ||
'created': isA<String>(), | ||
'members': [ | ||
{'email': '[email protected]', 'role': 'admin', 'userId': isA<String>()} | ||
] | ||
}); | ||
final p1 = await publisherBackend.getPublisher('other.com'); | ||
expect(p1, isNotNull); | ||
final rs2 = await client.adminInvokeAction('publisher-delete', | ||
AdminInvokeActionArguments(arguments: {'publisher': 'other.com'})); | ||
expect(rs2.output, { | ||
'message': 'Publisher and all members deleted.', | ||
'publisherId': 'other.com', | ||
'members-count': 1, | ||
}); | ||
final p2 = await publisherBackend.getPublisher('other.com'); | ||
expect(p2, isNull); | ||
}); | ||
|
||
testWithProfile('remove package from publisher', fn: () async { | ||
final api = createPubApiClient(authToken: siteAdminToken); | ||
final result = await api.adminInvokeAction( | ||
'publisher-package-remove', | ||
AdminInvokeActionArguments(arguments: {'package': 'neon'}), | ||
); | ||
final neon = await packageBackend.lookupPackage('neon'); | ||
|
||
expect(result.output, { | ||
'previousPublisher': 'example.com', | ||
'package': 'neon', | ||
'uploaders': [ | ||
{'email': '[email protected]', 'userId': neon!.uploaders!.first} | ||
] | ||
}); | ||
final packagePublisherInfo = | ||
await packageBackend.getPublisherInfo('neon'); | ||
expect(packagePublisherInfo.publisherId, isNull); | ||
final emails = await accountBackend.getEmailsOfUserIds(neon.uploaders!); | ||
expect(emails, {'[email protected]'}); | ||
}); | ||
}); | ||
} |