Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Can we have proper example of using this package? #21

Open
priyashpatil opened this issue Aug 2, 2021 · 1 comment
Open

Can we have proper example of using this package? #21

priyashpatil opened this issue Aug 2, 2021 · 1 comment

Comments

@priyashpatil
Copy link

priyashpatil commented Aug 2, 2021

I'm trying to figure out how to use the test handler but still that my-package is a complete black box for me. Can someone please share any working examples?

@priyashpatil
Copy link
Author

priyashpatil commented Aug 2, 2021

import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf_test_handler/shelf_test_handler.dart';
import 'package:test/test.dart';

import 'package:my_package/my_package.dart';

void main() {
  test("client performs protocol handshake", () async {
    // This is just a utility class that starts a server for a ShelfTestHandler.
    var server = new ShelfTestServer();

    // Asserts that the client will make a GET request to /token.
    server.handler.expect("GET", "/token", (request) async {
      // This handles the GET /token request.
      var body = JSON.parse(await request.readAsString());

      // Any failures in this handler will cause the test to fail, so it's safe
      // to make assertions.
      expect(body, containsPair("id", "my_package_id"));
      expect(body, containsPair("secret", "123abc"));

      return new shelf.Response.ok(JSON.encode({"token": "a1b2c3"}),
          headers: {"content-type": "application/json"});
    });

    // Requests made against `server.url` will be handled by the handlers we
    // declare.
    var myPackage = new MyPackage(server.url);

    // If the client makes any unexpected requests, the test will fail.
    await myPackage.performHandshake();
  });
}

How do I configure MyPackage?????

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant