Skip to content

Commit

Permalink
fix file test
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-lox committed Jan 20, 2025
1 parent e40542a commit 6fdc9c6
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions packages/ndk/test/usecases/files/files_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ void main() {
late Files client;

setUp(() async {
server = MockBlossomServer(port: 3008);
server2 = MockBlossomServer(port: 3009);
server = MockBlossomServer(port: 3010);
server2 = MockBlossomServer(port: 3011);
await server.start();
await server2.start();

Expand Down Expand Up @@ -47,54 +47,58 @@ void main() {
// download
final getResponse = client.download(
url: 'http://localhost:3000/no_file',
serverUrls: ['http://localhost:3000'],
serverUrls: ['http://localhost:3010'],
);
expect(getResponse, throwsA(isA<Exception>()));
});

test('Upload and retrieve file', () async {
final testData = Uint8List.fromList(utf8.encode('Hello, File'));
final testData = Uint8List.fromList(utf8.encode('Hello, File2'));

// Upload
final uploadResponse = await client.upload(
file: NdkFile(data: testData, mimeType: 'text/plain'),
serverUrls: ['http://localhost:3000'],
serverUrls: ['http://localhost:3010'],
);
expect(uploadResponse.first.success, true);

final sha256 = uploadResponse.first.descriptor!.sha256;

// download
final getResponse = await client.download(
url: 'http://localhost:3000/$sha256',
serverUrls: ['http://localhost:3000'],
url: 'http://localhost:3010/$sha256',
serverUrls: ['http://localhost:3010'],
);
expect(utf8.decode(getResponse.data), equals('Hello, File'));

expect(utf8.decode(getResponse.data), equals('Hello, File2'));
});

test('Upload and delete file', () async {
final testData = Uint8List.fromList(utf8.encode('Hello, File'));
final testData = Uint8List.fromList(utf8.encode('Hello, File2'));

// Upload
final uploadResponse = await client.upload(
file: NdkFile(data: testData, mimeType: 'text/plain'),
serverUrls: ['http://localhost:3000'],
serverUrls: ['http://localhost:3010'],
);
expect(uploadResponse.first.success, true);

final sha256 = uploadResponse.first.descriptor!.sha256;

final deleteResponse = await client.delete(
sha256: sha256,
serverUrls: ['http://localhost:3000'],
serverUrls: ['http://localhost:3010', 'http://localhost:3011'],
);

expect(deleteResponse.first.success, true);

// download
final getResponse = client.download(
url: 'http://localhost:3000/$sha256',
serverUrls: ['http://localhost:3000'],
url: 'http://localhost:3010/$sha256',
serverUrls: [
'https://localhost:3011',
'http://localhost:3010',
],
);
expect(getResponse, throwsA(isA<Exception>()));
});
Expand Down

0 comments on commit 6fdc9c6

Please sign in to comment.