Skip to content

Commit

Permalink
Remove duplicate tests in sentry_client_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Oct 29, 2024
1 parent 7954fb3 commit 5244e55
Showing 1 changed file with 13 additions and 80 deletions.
93 changes: 13 additions & 80 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1658,85 +1658,6 @@ void main() {
expect(envelope.clientReport, clientReport);
});

test('captureEvent adds trace context', () async {
final client = fixture.getSut();

final scope = Scope(fixture.options);
scope.replayId = SentryId.newId();
scope.span =
SentrySpan(fixture.tracer, fixture.tracer.context, MockHub());

await client.captureEvent(fakeEvent, scope: scope);

final envelope = fixture.transport.envelopes.first;
expect(envelope.header.traceContext, isNotNull);
expect(envelope.header.traceContext?.replayId, scope.replayId);
});

test('captureEvent adds attachments from hint', () async {
final attachment = SentryAttachment.fromIntList([], "fixture-fileName");
final hint = Hint.withAttachment(attachment);

final sut = fixture.getSut();
await sut.captureEvent(fakeEvent, hint: hint);

final capturedEnvelope = (fixture.transport).envelopes.first;
final attachmentItem = IterableUtils.firstWhereOrNull(
capturedEnvelope.items,
(SentryEnvelopeItem e) => e.header.type == SentryItemType.attachment,
);
expect(attachmentItem?.header.attachmentType,
SentryAttachment.typeAttachmentDefault);
});

test('captureEvent adds screenshot from hint', () async {
final client = fixture.getSut();
final screenshot =
SentryAttachment.fromScreenshotData(Uint8List.fromList([0, 0, 0, 0]));
final hint = Hint.withScreenshot(screenshot);

await client.captureEvent(fakeEvent, hint: hint);

final capturedEnvelope = (fixture.transport).envelopes.first;
final attachmentItem = capturedEnvelope.items.firstWhereOrNull(
(element) => element.header.type == SentryItemType.attachment);
expect(attachmentItem?.header.fileName, 'screenshot.png');
});

test('captureEvent adds viewHierarchy from hint', () async {
final client = fixture.getSut();
final view = SentryViewHierarchy('flutter');
final attachment = SentryAttachment.fromViewHierarchy(view);
final hint = Hint.withViewHierarchy(attachment);

await client.captureEvent(fakeEvent, hint: hint);

final capturedEnvelope = (fixture.transport).envelopes.first;
final attachmentItem = capturedEnvelope.items.firstWhereOrNull(
(element) => element.header.type == SentryItemType.attachment);

expect(attachmentItem?.header.attachmentType,
SentryAttachment.typeViewHierarchy);
});

test('captureTransaction adds trace context', () async {
final client = fixture.getSut();

final tr = SentryTransaction(fixture.tracer);

final context = SentryTraceContextHeader.fromJson(<String, dynamic>{
'trace_id': '${tr.eventId}',
'public_key': '123',
'replay_id': '456',
});

await client.captureTransaction(tr, traceContext: context);

final envelope = fixture.transport.envelopes.first;
expect(envelope.header.traceContext, isNotNull);
expect(envelope.header.traceContext?.replayId, SentryId.fromId('456'));
});

test('captureUserFeedback calls flush', () async {
final client = fixture.getSut(eventProcessor: DropAllEventProcessor());

Expand Down Expand Up @@ -1953,6 +1874,14 @@ void main() {

expect(capturedEnvelope.header.dsn, fixture.options.dsn);
});
});

group('Spotlight', () {
late Fixture fixture;

setUp(() {
fixture = Fixture();
});

test(
'Spotlight enabled should not set transport to SpotlightHttpTransport on iOS',
Expand Down Expand Up @@ -2034,13 +1963,15 @@ void main() {
final client = fixture.getSut();

final scope = Scope(fixture.options);
scope.replayId = SentryId.newId();
scope.span =
SentrySpan(fixture.tracer, fixture.tracer.context, MockHub());

await client.captureEvent(fakeEvent, scope: scope);

final envelope = fixture.transport.envelopes.first;
expect(envelope.header.traceContext, isNotNull);
expect(envelope.header.traceContext?.replayId, scope.replayId);
});

test('captureTransaction adds trace context', () async {
Expand All @@ -2051,12 +1982,14 @@ void main() {
final context = SentryTraceContextHeader.fromJson(<String, dynamic>{
'trace_id': '${tr.eventId}',
'public_key': '123',
'replay_id': '456',
});

await client.captureTransaction(tr, traceContext: context);

final envelope = fixture.transport.envelopes.first;
expect(envelope.header.traceContext, isNotNull);
expect(envelope.header.traceContext?.replayId, SentryId.fromId('456'));
});

test('captureFeedback adds trace context', () async {
Expand Down Expand Up @@ -2090,7 +2023,7 @@ void main() {
final capturedEnvelope = (fixture.transport).envelopes.first;
final attachmentItem = IterableUtils.firstWhereOrNull(
capturedEnvelope.items,
(SentryEnvelopeItem e) => e.header.type == SentryItemType.attachment,
(SentryEnvelopeItem e) => e.header.type == SentryItemType.attachment,
);
expect(attachmentItem?.header.attachmentType,
SentryAttachment.typeAttachmentDefault);
Expand Down

0 comments on commit 5244e55

Please sign in to comment.