diff --git a/packages/shorebird_cli/lib/src/commands/publish_command.dart b/packages/shorebird_cli/lib/src/commands/publish_command.dart index bcb796aa..ab3ebbfc 100644 --- a/packages/shorebird_cli/lib/src/commands/publish_command.dart +++ b/packages/shorebird_cli/lib/src/commands/publish_command.dart @@ -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, diff --git a/packages/shorebird_cli/test/src/commands/publish_command_test.dart b/packages/shorebird_cli/test/src/commands/publish_command_test.dart index 0b4a872a..1071cb36 100644 --- a/packages/shorebird_cli/test/src/commands/publish_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/publish_command_test.dart @@ -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'), diff --git a/packages/shorebird_code_push_client/example/main.dart b/packages/shorebird_code_push_client/example/main.dart index df965cd2..762e5610 100644 --- a/packages/shorebird_code_push_client/example/main.dart +++ b/packages/shorebird_code_push_client/example/main.dart @@ -34,8 +34,8 @@ Future 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: '', // e.g. 'libapp.so' platform: '', // e.g. 'android' diff --git a/packages/shorebird_code_push_client/lib/src/code_push_client.dart b/packages/shorebird_code_push_client/lib/src/code_push_client.dart index 7a47bca0..a4a6835b 100644 --- a/packages/shorebird_code_push_client/lib/src/code_push_client.dart +++ b/packages/shorebird_code_push_client/lib/src/code_push_client.dart @@ -47,7 +47,7 @@ class CodePushClient { Map get _apiKeyHeader => {'x-api-key': _apiKey}; /// Create a new artifact for a specific [patchId]. - Future createArtifact({ + Future 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); + return PatchArtifact.fromJson(json.decode(body) as Map); } /// Create a new app with the provided [displayName]. diff --git a/packages/shorebird_code_push_client/test/src/code_push_client_test.dart b/packages/shorebird_code_push_client/test/src/code_push_client_test.dart index ff8fee81..e1f1b9b9 100644 --- a/packages/shorebird_code_push_client/test/src/code_push_client_test.dart +++ b/packages/shorebird_code_push_client/test/src/code_push_client_test.dart @@ -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() + isA() .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', + ), ); }); });