refactor(shorebird_cli): use createPatchArtifact (#184)
This commit is contained in:
@@ -202,7 +202,7 @@ ${styleBold.wrap(lightGreen.wrap('🚀 Ready to publish a new patch!'))}
|
||||
|
||||
final createArtifactProgress = logger.progress('Creating artifact');
|
||||
try {
|
||||
await codePushClient.createArtifact(
|
||||
await codePushClient.createPatchArtifact(
|
||||
patchId: patch.id,
|
||||
artifactPath: artifact.path,
|
||||
arch: _arch,
|
||||
|
||||
@@ -33,7 +33,7 @@ void main() {
|
||||
const appDisplayName = 'Test App';
|
||||
const app = App(id: appId, displayName: appDisplayName);
|
||||
const appMetadata = AppMetadata(appId: appId, displayName: appDisplayName);
|
||||
const artifact = Artifact(
|
||||
const patchArtifact = PatchArtifact(
|
||||
id: 0,
|
||||
patchId: 0,
|
||||
arch: 'aarch64',
|
||||
@@ -143,14 +143,14 @@ flutter:
|
||||
() => codePushClient.createPatch(releaseId: any(named: 'releaseId')),
|
||||
).thenAnswer((_) async => patch);
|
||||
when(
|
||||
() => codePushClient.createArtifact(
|
||||
() => codePushClient.createPatchArtifact(
|
||||
artifactPath: any(named: 'artifactPath'),
|
||||
patchId: any(named: 'patchId'),
|
||||
arch: any(named: 'arch'),
|
||||
platform: any(named: 'platform'),
|
||||
hash: any(named: 'hash'),
|
||||
),
|
||||
).thenAnswer((_) async => artifact);
|
||||
).thenAnswer((_) async => patchArtifact);
|
||||
when(
|
||||
() => codePushClient.promotePatch(
|
||||
patchId: any(named: 'patchId'),
|
||||
@@ -425,13 +425,13 @@ flutter:
|
||||
expect(exitCode, ExitCode.software.code);
|
||||
});
|
||||
|
||||
test('throws error when uploading artifact fails.', () async {
|
||||
test('throws error when uploading patch artifact fails.', () async {
|
||||
const error = 'something went wrong';
|
||||
when(
|
||||
() => codePushClient.getReleases(appId: any(named: 'appId')),
|
||||
).thenAnswer((_) async => []);
|
||||
when(
|
||||
() => codePushClient.createArtifact(
|
||||
() => codePushClient.createPatchArtifact(
|
||||
artifactPath: any(named: 'artifactPath'),
|
||||
patchId: any(named: 'patchId'),
|
||||
arch: any(named: 'arch'),
|
||||
|
||||
@@ -34,8 +34,8 @@ Future<void> main() async {
|
||||
// Create a new patch.
|
||||
final patch = await client.createPatch(releaseId: release.id);
|
||||
|
||||
// Create an artifact.
|
||||
final artifact = await client.createArtifact(
|
||||
// Create a patch artifact.
|
||||
final patchArtifact = await client.createPatchArtifact(
|
||||
patchId: patch.id,
|
||||
artifactPath: '<PATH TO ARTIFACT>', // e.g. 'libapp.so'
|
||||
platform: '<PLATFORM>', // e.g. 'android'
|
||||
|
||||
@@ -47,7 +47,7 @@ class CodePushClient {
|
||||
Map<String, String> get _apiKeyHeader => {'x-api-key': _apiKey};
|
||||
|
||||
/// Create a new artifact for a specific [patchId].
|
||||
Future<Artifact> createArtifact({
|
||||
Future<PatchArtifact> createPatchArtifact({
|
||||
required String artifactPath,
|
||||
required int patchId,
|
||||
required String arch,
|
||||
@@ -56,12 +56,11 @@ class CodePushClient {
|
||||
}) async {
|
||||
final request = http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse('$hostedUri/api/v1/artifacts'),
|
||||
Uri.parse('$hostedUri/api/v1/patches/$patchId/artifacts'),
|
||||
);
|
||||
final file = await http.MultipartFile.fromPath('file', artifactPath);
|
||||
request.files.add(file);
|
||||
request.fields.addAll({
|
||||
'patch_id': '$patchId',
|
||||
'arch': arch,
|
||||
'platform': platform,
|
||||
'hash': hash,
|
||||
@@ -73,7 +72,7 @@ class CodePushClient {
|
||||
|
||||
if (response.statusCode != HttpStatus.ok) throw _parseErrorResponse(body);
|
||||
|
||||
return Artifact.fromJson(json.decode(body) as Map<String, dynamic>);
|
||||
return PatchArtifact.fromJson(json.decode(body) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
/// Create a new app with the provided [displayName].
|
||||
|
||||
@@ -56,7 +56,7 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('createArtifact', () {
|
||||
group('createPatchArtifact', () {
|
||||
const patchId = 0;
|
||||
const arch = 'aarch64';
|
||||
const platform = 'android';
|
||||
@@ -76,7 +76,7 @@ void main() {
|
||||
..createSync();
|
||||
|
||||
expect(
|
||||
codePushClient.createArtifact(
|
||||
codePushClient.createPatchArtifact(
|
||||
artifactPath: fixture.path,
|
||||
patchId: patchId,
|
||||
arch: arch,
|
||||
@@ -106,7 +106,7 @@ void main() {
|
||||
..createSync();
|
||||
|
||||
expect(
|
||||
codePushClient.createArtifact(
|
||||
codePushClient.createPatchArtifact(
|
||||
artifactPath: fixture.path,
|
||||
patchId: patchId,
|
||||
arch: arch,
|
||||
@@ -131,7 +131,7 @@ void main() {
|
||||
Stream.value(
|
||||
utf8.encode(
|
||||
json.encode(
|
||||
Artifact(
|
||||
PatchArtifact(
|
||||
id: artifactId,
|
||||
url: artifactUrl,
|
||||
patchId: patchId,
|
||||
@@ -152,7 +152,7 @@ void main() {
|
||||
..createSync();
|
||||
|
||||
await expectLater(
|
||||
codePushClient.createArtifact(
|
||||
codePushClient.createPatchArtifact(
|
||||
artifactPath: fixture.path,
|
||||
patchId: patchId,
|
||||
arch: arch,
|
||||
@@ -161,7 +161,7 @@ void main() {
|
||||
),
|
||||
completion(
|
||||
equals(
|
||||
isA<Artifact>()
|
||||
isA<PatchArtifact>()
|
||||
.having((a) => a.id, 'id', artifactId)
|
||||
.having((a) => a.patchId, 'patchId', patchId)
|
||||
.having((a) => a.arch, 'arch', arch)
|
||||
@@ -178,7 +178,9 @@ void main() {
|
||||
|
||||
expect(
|
||||
request.url,
|
||||
codePushClient.hostedUri.replace(path: '/api/v1/artifacts'),
|
||||
codePushClient.hostedUri.replace(
|
||||
path: '/api/v1/patches/$patchId/artifacts',
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user