text: "use strict";
  
  const Bell = require("../..");
  const Code = require("@hapi/code");
  const Hapi = require("@hapi/hapi");
  const Hoek = require("@hapi/hoek");
  const Lab = require("@hapi/lab");
  
  const Mock = require("../mock");
  
  const internals = {};
  
  const { describe, it } = (exports.lab = Lab.script());
  const expect = Code.expect;
  
  describe("reddit", () => {
    it("authenticates with mock", async (flags) => {
      const mock = await Mock.v2(flags);
      const server = Hapi.server({ host: "localhost", port: 80 });
      await server.register(Bell);
  
      const custom = Bell.providers.reddit();
      Hoek.merge(custom, mock.provider);
  
      const profile = {
        name: "john",
        created: 0,
        created_utc: 0,
        hide_from_robots: true,
        gold_creddits: 0,
        link_karma: 0,
        comment_karma: 0,
        over_18: true,
        is_gold: false,
        is_mod: true,
        gold_expiration: null,
        has_verified_email: true,
        id: "abcde",
        inbox_count: 0,
      };
  
      Mock.override("https://oauth.reddit.com/api/v1/me", profile);
  
      server.auth.strategy("custom", "bell", {
        password: "cookie_encryption_password_secure",
        isSecure: false,
        clientId: "reddit",
        clientSecret: "secret",
        provider: custom,
      });
  
      server.route({
        method: "*",
        path: "/login",
        config: {
          auth: "custom",
          handler: function (request, h) {
            return request.auth.credentials;
          },
        },
      });
  
      const res1 = await server.inject("/login");
      const cookie = res1.headers["set-cookie"][0].split(";")[0] + ";";
  
      const res2 = await mock.server.inject(res1.headers.location);
  
      const res3 = await server.inject({
        url: res2.headers.location,
        headers: { cookie },
      });
      expect(res3.result).to.equal({
        provider: "custom",
        token: "456",
        expiresIn: 3600,
        refreshToken: undefined,
        query: {},
        state: { query: {} },
        profile,
      });
    });
  });
  