Skip to main content

gmconsult_dev 0.0.6 copy "gmconsult_dev: ^0.0.6" to clipboard
gmconsult_dev: ^0.0.6 copied to clipboard

unlistedoutdated

DART utilities for GM Consult developers to generate code and lubricate / standardize unit testing.

gmconsult_dev #

GM Consult Pty Ltd

Generate code and lubricate / standardize unit testing. #

THIS PACKAGE IS A PROPRIETARY, UNLISTED RESOURCE AND SUBJECT TO BREAKING CHANGES WITHOUT NOTICE.

Skip to section:

Overview #

A collection of utilities used for unit testing and code generation. May require knowledge of GM Consult coding practices and management systems:

  • Use the Echo class to print a collection JSON documents to the console as a formatted table.
  • Use the SaveAs class to save text and JSON documents to disk.
  • Use datasets from the TestData class in your unit tests.
  • Use the JsonDataService class to quickly create and populate a asynchronous persisted datastore.
  • Use the static methods from API to GET or POST from/to a RESTful API.

Usage #

Fully worked examples are included in the package.

In the pubspec.yaml of your flutter project, add the following dev dependency:

dev_dependencies:
  gmconsult_dev: <latest_version>

In your test file add the following import:

// import the `Echo`, `SaveAs` and `JsonDataService` classes
import 'package:gmconsult_dev/gmconsult_dev.dart';

// import the typedefs if needed
import 'package:gmconsult_dev/type_definitions.dart';

// import the `TestData` datasets if needed
import 'package:gmconsult_dev/test_data.dart';

Pass a collection of JSON documents to the Echo() unnamed factory constructor and call printResults:


// a sample list of JSON documents
final json =[
  {'Key':'item 1', 'Value': 1.3456},
  {'Key':'item 2', 'Value': 7.89}
];

// pass a title and results to a Echo instance and call printResults
Echo(title: 'MY TEST NAME', results: json).printResults();

// prints:
// —————————————————————————————————————————————————————————————————————————————————
// MY TEST NAME                                                                     
// _________________________________________________________________________________
// │  Key                                  │                 Value                 │
// —————————————————————————————————————————————————————————————————————————————————
// │  item 1                               │                               1.3456  │
// │  item 2                               │                               7.8900  │
// —————————————————————————————————————————————————————————————————————————————————

//

Mock a data service with JsonDataService #

Initialize a JsonDataService, populate it and then read from it.


  // get some data
  final jsonCollection = {
    'term0': {'term': 'bodrer', 'dL': 0.0, 'cLs': 1.0},
    'term1': {'term': 'board', 'dL': 0.26303837, 'cLs': 0.736},
    'term2': {'term': 'border', 'dL': 0.0, 'cLs': 1.0},
    'term3': {'term': 'boarder', 'dL': 0.222395656, 'cLs': 0.77761454},
    'term4': {'term': 'brother', 'dL': 0.22239353904, 'cLs': 0.7776134576},
    'term5': {'term': 'broad', 'dL': 0.263035476, 'cLs': 0.73697546},
    'term6': {'term': 'bored', 'dL': 0.2630354, 'cLs': 0.7369766},
  };

  // instantiate a JsonDataService
  final service = await JsonDataService.hydrate(
      '${Directory.current.path}\\example', 'sampleStocks');

  // clear the datastore
  await service.dataStore.clear();

  // add all the elements of sampleStocks
  await service.batchUpsert(jsonCollection);

  // read a few records
  final results = (await service.batchRead(['term3', 'term5'])).values.toList();

  // print the records
  Echo(title: 'JSON DATA SERVICE', results: results).printResults();

  // close the service, releasing the resources
  await service.close();

  // prints:
  // ———————————————————————————————————————————————————————————————————————————————————
  // JSON DATA SERVICE                                                                  
  // ___________________________________________________________________________________
  // │  term                  │             dL             │            cLs            │
  // ———————————————————————————————————————————————————————————————————————————————————
  // │  boarder               │                   0.22240  │                  0.77761  │
  // │  broad                 │                   0.26304  │                  0.73698  │
  // ———————————————————————————————————————————————————————————————————————————————————

Save test results SaveAs using TestData #

To save text, JSON or test results, just call the appropriate static method from the SaveAs class. We are using datasets from the TestData class in the examples below.


      // save text from a `TestData` dataset
      await SaveAs.text(
        fileName: 'test/data/google',
        text: TestData.text,
      );

      // save a JSON document from a `TestData` dataset
      await SaveAs.json(
        fileName: 'test/data/google',
        json: TestData.json,
      );

      // save your TestResults collection from a `TestData` dataset
      await SaveAs.results(
        fileName: 'test/data/results',
        results: TestData.stockData.values,
        keyBuilder: (json) => json['id'],
      );

Use the static methods from API to GET some data from a RESTful API:

  // Get some JSON data from a public API endpoint
  final json = await API.get(
      host: 'boredapi.com',
      path: 'api/activity',
      queryParameters: {'key': '5881028'},
      // headers: headers,
      isHttps: true);

  // print the results
  print('Request URL:        ${json['_%url']}');
  print('Response code:      ${json['_%status']}');
  print('Activity:           ${json['activity']}');

  // prints to the console:
  //    Request URL:        https://boredapi.com/api/activity?key=5881028
  //    Response code:      200
  //    Activity:           Learn a new programming language

API #

API documentation is available on pub.dev.

Definitions #

None

References #

None

Issues #

GM Consult team members should log issues and bugs.

This project is an internal package for GM Consult projects and we cannot respond to pull requests or issues raised by non team members.

0
likes
0
points
17
downloads

Publisher

verified publishergmconsult.dev

Weekly Downloads

DART utilities for GM Consult developers to generate code and lubricate / standardize unit testing.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, hive, http

More

Packages that depend on gmconsult_dev