it("should fetch invoices", async () => {
    if (!schema) {
      throw new Error("Invoice schema not generated");
    }

    const { state: { token } } = store;

    const resp = await Billing.Invoices.getCollection({
      token,
      query: {},
      settings: {
        url: process.env.API_URL || "",
        project: process.env.PROJECT_ID || "",
      },
    });

    if (!resp.ok) {
      throw new Error(resp.error.title);
    }

    if (!resp.value.data) {
      throw new Error("data field is empty");
    }

    assert.isTrue(resp.ok);
    assert.jsonSchema(resp.value, schema);
  });
    it("should fetch a token", async () => {
      const totpToken = totp({
        secret: process.env.TOTP_SECRET,
        encoding: "base32",
        // tslint:disable-next-line:no-bitwise
        time: (Date.now() / 1000) | 0, // specified in seconds
      });

      const resp = await Auth.passwordGrant(
        {
          email: process.env.EMAIL || "",
          password: process.env.PASSWORD || "",
          client_id: process.env.CLIENT_ID,
          client_secret: process.env.CLIENT_SECRET,
          totp_passcode: totpToken,
        },
        {
          url: process.env.AUTH_URL,
          noVersion: true,
          useHttp: store.state.settings.useHttp,
        },
      );

      if (!resp.ok) {
        throw new Error(resp.error.title);
      }

      assert.isTrue(resp.ok);
      assert.jsonSchema(resp.value, schema);

      // use this token for subsequent requests
      store.updateToken(resp.value);
    });
Example #3
0
	export function assertConfig(config:tsd.Config, values:any, message:string) {
		assert.ok(config, message + ': config');
		assert.ok(values, message + ': values');
		assert.instanceOf(config, tsd.Config, message + ': config');

		helper.propStrictEqual(config, values, 'path', message);
		helper.propStrictEqual(config, values, 'version', message);
		helper.propStrictEqual(config, values, 'repo', message);
		helper.propStrictEqual(config, values, 'ref', message);

		if (values.repoOwner) {
			helper.propStrictEqual(config, values, 'repoOwner', message);
		}
		if (values.repoProject) {
			helper.propStrictEqual(config, values, 'repoProject', message);
		}

		var json = config.toJSON();
		assert.jsonSchema(json, helper.getConfigSchema(), message + ': schema');
		helper.propStrictEqual(json, values, 'path', message + ': json');
		helper.propStrictEqual(json, values, 'version', message + ': json');
		helper.propStrictEqual(json, values, 'repo', message + ': json');
		helper.propStrictEqual(json, values, 'ref', message + ': json');
		if (values.installed) {
			assert.like(json.installed, values.installed);
		}
		else {
			assert.like(json.installed, {});
		}
	}
  it("should update account name and revert it back", async () => {
    const { token } = store.state;
    const originalResp = await Account.getSingle({
      token,
      settings: { url: process.env.API_URL },
    });

    if (!originalResp.ok) {
      throw new Error(originalResp.error.title);
    }

    if (!originalResp.value.data) {
      throw new Error("data field is null");
    }

    const value = {
      name: {
        first: "Mike",
        last: "Wizowsky",
      },
    };

    const resp = await Account.update({
      token,
      value,

      query: {},
      settings: { url: process.env.API_URL },
    });

    if (!resp.ok) {
      throw new Error(resp.error.title);
    }

    assert.isTrue(resp.ok);
    assert.jsonSchema(resp.value.data, schema);
    assert.deepPropertyVal(resp.value.data, "name", {
      first: "Mike",
      last: "Wizowsky",
    });

    const revertUpdate = { name: originalResp.value.data.name };
    const revertResp = await Account.update({
      token,
      query: {},
      value: revertUpdate,
      settings: { url: process.env.API_URL },
    });

    if (!revertResp.ok) {
      throw new Error(revertResp.error.title);
    }

    assert.deepPropertyVal(revertResp.value.data, "name", revertUpdate.name);
  });
  it("should fetch project capabilities", async () => {
    if (!schema) {
      throw new Error("Capabilities schema not generated");
    }

    const resp = await Projects.getCapabilities({
      settings: store.state.settings,
    });

    if (!resp.ok) {
      throw new Error(resp.error.title);
    }

    assert.isTrue(resp.ok);
    assert.jsonSchema(resp.value, schema);
  });
  it("should fetch user account", async () => {
    if (!schema) {
      throw new Error("Account schema not generated");
    }
    const { token } = store.state;

    const resp = await Account.getSingle({
      token,
      query: {},
      settings: { url: process.env.API_URL },
    });

    if (!resp.ok) {
      throw new Error(resp.error.title);
    }

    assert.isTrue(resp.ok);
    assert.jsonSchema(resp.value.data, schema);
  });
  it("should fetch notifications", async () => {
    if (!schema) {
      throw new Error("Notification schema not generated");
    }

    const { state: { token } } = store;

    const resp = await Notifications.getCollection({
      token,
      settings: store.state.settings,
    });

    if (!resp.ok) {
      throw new Error(resp.error.title);
    }

    assert.isTrue(resp.ok);
    assert.jsonSchema(resp.value, schema);
  });
  it("should fetch provider datacenters", async () => {
    if (!schema) {
      throw new Error("DC schema not generated");
    }

    const { active: { provider } } = store.state;

    const resp = await Infrastructure.Providers.DataCenters.getCollection({
      provider,
      query: {},
      settings: store.state.settings,
    });

    if (!resp.ok) {
      throw new Error(resp.error.title);
    }

    assert.isTrue(resp.ok);
    assert.jsonSchema(resp.value, schema);
  });
  it("should delete the environment we created", async () => {
    const { token } = store.state;
    const resp = await Environments.remove({
      token,
      id: store.state.active.environment,
      query: {},
      settings: store.state.settings,
    });

    if (!resp.ok) {
      throw new Error(resp.error.title);
    }

    if (!resp.value.data) {
      throw new Error("data field is empty");
    }

    assert.isTrue(resp.ok);
    assert.jsonSchema(resp.value.data, schema);
  });
Example #10
0
			}).then((first) => {
				assert.ok(first, 'first data');
				assert.isObject(first, 'first data');
				assert.strictEqual(first.sha, expectedSha, 'first.sha vs expectedSha');

				assert.jsonSchema(first, metaFields, 'first meta');
				fixMeta(first.meta);
				assert.jsonOf(expectedJson, first, 'first vs expectedJson');

				var firstBuffer = git.GitUtil.decodeBlobJson(first);
				assert.instanceOf(firstBuffer, Buffer, 'buffer');

				var firstSha = git.GitUtil.blobShaHex(firstBuffer);
				assert.strictEqual(firstSha, expectedSha, 'firstSha vs expected');

				// get again, should be cached
				return repo.api.getBlob(expectedSha).progress((note:any) => {
					notes.push(note);
				}).then((second) => {
					assert.ok(second, 'second data');
					assert.isObject(second, 'second data');
					assert.strictEqual(second.sha, expectedSha, 'second.sha vs expectedSha');

					var secondBuffer = git.GitUtil.decodeBlobJson(first);
					assert.instanceOf(secondBuffer, Buffer, 'buffer');
					var secondSha = git.GitUtil.blobShaHex(secondBuffer);
					assert.strictEqual(secondSha, expectedSha, 'secondSha vs expected');

					helper.assertNotes(notes, [
						{
							message: /^remote: /,
							code: 'http 200'
						},
						{
							message: /^local: /,
							code: null
						}
					], 'second');
				});
			});