Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
contexts test, fix bug, missing field in device
  • Loading branch information
maks committed Jan 10, 2020
commit 08e51f3fd6a475558ae0f2a4652dc5463733f960
4 changes: 3 additions & 1 deletion lib/src/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,14 @@ class Device {

if (storageSize != null) json['storage_size'] = storageSize;

if (freeStorage != null) json['free_storage'] = freeStorage;

if (externalStorageSize != null) {
json['external_storage_size'] = externalStorageSize;
}

if (externalFreeStorage != null) {
json['exterenal_free_storage'] = externalFreeStorage;
json['external_free_storage'] = externalFreeStorage;
}

if (bootTime != null) json['boot_time'] = bootTime.toIso8601String();
Expand Down
95 changes: 95 additions & 0 deletions test/contexts_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:sentry/sentry.dart';
import 'package:test/test.dart';

void main() {
group(Contexts, () {
test('serializes to JSON', () {
final testDevice = Device(
name: 'testDevice',
family: 'testFamily',
model: 'testModel',
modelId: 'testModelId',
arch: 'testArch',
batteryLevel: 23,
orientation: Orientation.landscape,
manufacturer: 'testOEM',
brand: 'testBrand',
screenResolution: '123x345',
screenDensity: '99',
screenDpi: '100',
online: false,
charging: true,
lowMemory: false,
simulator: true,
memorySize: 1234567,
freeMemory: 12345,
usableMemory: 9876,
storageSize: 1234567,
freeStorage: 1234567,
externalStorageSize: 98765,
externalFreeStorage: 98765,
bootTime: DateTime.fromMicrosecondsSinceEpoch(0),
timezone: 'Australia/Melbourne',
);
final testOS = OperatingSystem(name: 'testOS');
final testRuntimes = [
Runtime(name: 'testRT1', version: '1.0'),
Runtime(name: 'testRT2', version: '2.3.1'),
];
final testApp = App(version: '1.2.3');
final testBrowser = Browser(version: '12.3.4');

final contexts = Contexts(
device: testDevice,
operatingSystem: testOS,
runtimes: testRuntimes,
app: testApp,
browser: testBrowser,
);

expect(
contexts.toJson(),
<String, dynamic>{
'device': {
'name': 'testDevice',
'family': 'testFamily',
'model': 'testModel',
'model_id': 'testModelId',
'arch': 'testArch',
'battery_level': 23,
'orientation': 'landscape',
'manufacturer': 'testOEM',
'brand': 'testBrand',
'screen_resolution': '123x345',
'screen_density': '99',
'screen_dpi': '100',
'online': false,
'charging': true,
'low_memory': false,
'simulator': true,
'memory_size': 1234567,
'free_memory': 12345,
'usable_memory': 9876,
'storage_size': 1234567,
'free_storage': 1234567,
'external_storage_size': 98765,
'external_free_storage': 98765,
'boot_time': '1970-01-01T10:00:00.000',
'timezone': 'Australia/Melbourne',
},
'os': {
'name': 'testOS',
},
'testrt1': {'name': 'testRT1', 'type': 'runtime', 'version': '1.0'},
'testrt2': {'name': 'testRT2', 'type': 'runtime', 'version': '2.3.1'},
'app': {'app_version': '1.2.3'},
'browser': {'version': '12.3.4'},
},
);
});
});
}