<commit_before>import * as contents from "../src/contents";
import { AjaxObservable } from "./types";

const serverConfig = {
  endpoint: "http://localhost:8888",
  crossDomain: true,
  token: "secret-token"
};
describe("contents", () => {
  describe("remove", () => {
    test("creates the AjaxObservable for removing contents", () => {
      const remove$ = contents.remove(
        serverConfig,
        "/path.ipynb"
      ) as AjaxObservable;
      const request = remove$.request;
      expect(request.url).toBe("http://localhost:8888/api/contents/path.ipynb");
      expect(request.method).toBe("DELETE");
    });
  });
  describe("get", () => {
    test("creates the AjaxObservable for getting content", () => {
      const content$ = contents.get(
        serverConfig,
        "/walla/walla/bingbang.ipynb"
      ) as AjaxObservable;
      const request = content$.request;
      expect(request.url).toEqual(
        expect.stringContaining(
          "http://localhost:8888/api/contents/walla/walla/bingbang.ipynb?_="
        )
      );
      expect(request.method).toBe("GET");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
    test("creates the AjaxObservable for getting content with query parameters", () => {
      const content$ = contents.get(serverConfig, "/walla/walla", {
        type: "directory"
      }) as AjaxObservable;
      const request = content$.request;
      expect(request.url).toEqual(
        expect.stringContaining(
          "http://localhost:8888/api/contents/walla/walla?type=directory&_="
        )
      );
      expect(request.method).toBe("GET");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });

  describe("update", () => {
    test("creates the AjaxObservable for renaming a file", () => {
      const model = { path: "renamed/path" };
      const content$ = contents.update(serverConfig, "/path/to/rename", model);
      const request = (content$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/path/to/rename"
      );
      expect(request.method).toBe("PATCH");
      expect(request.body).toEqual(model);
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });

  describe("create", () => {
    test("creates the AjaxObservable for creating content", () => {
      const model = {
        type: "notebook",
        name: "c.ipynb",
        writable: true,
        content: {},
        format: "json"
      };
      const create$ = contents.create(serverConfig, "/a/b/c.ipynb", model);
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/a/b/c.ipynb"
      );
      expect(request.method).toBe("POST");
      expect(request.headers).toEqual({
        Authorization: "token secret-token",
        "Content-Type": "application/json"
      });
      expect(request.body).toEqual(model);
    });
  });

  describe("save", () => {
    test("creates the AjaxObservable for saving a file", () => {
      const model = {
        path: "save/to/this/path"
      };
      const create$ = contents.save(serverConfig, "/path/to/content", model);
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/path/to/content"
      );
      expect(request.method).toBe("PUT");
      expect(request.body).toEqual(model);
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });
  describe("listCheckpoints", () => {
    test("creates the AjaxObservable for listing checkpoints of a file", () => {
      const create$ = contents.listCheckpoints(
        serverConfig,
        "/path/to/content"
      );
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toEqual(
        expect.stringContaining(
          "http://localhost:8888/api/contents/path/to/content/checkpoints?_="
        )
      );
      expect(request.method).toBe("GET");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });
  describe("createCheckpoint", () => {
    test("creates the AjaxObservable for", () => {
      const create$ = contents.createCheckpoint(
        serverConfig,
        "/path/to/content"
      );
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/path/to/content/checkpoints"
      );
      expect(request.method).toBe("POST");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });
  describe("deleteCheckpoint", () => {
    test("creates the AjaxObservable for", () => {
      const create$ = contents.deleteCheckpoint(
        serverConfig,
        "/path/to/content",
        "id"
      );
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/path/to/content/checkpoints/id"
      );
      expect(request.method).toBe("DELETE");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });
  describe("restoreFromCheckpoint", () => {
    test("creates the AjaxObservable for", () => {
      const create$ = contents.restoreFromCheckpoint(
        serverConfig,
        "/path/to/content",
        "id"
      );
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/path/to/content/checkpoints/id"
      );
      expect(request.method).toBe("POST");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });
});
<commit_msg>Update rx-jupyter test to increase coverage<commit_after>import { JupyterContentProvider } from "../src/contents";
import { AjaxObservable } from "./types";

const serverConfig = {
  endpoint: "http://localhost:8888",
  crossDomain: true,
  token: "<PASSWORD>"
};
describe("contents", () => {
  describe("remove", () => {
    test("creates the AjaxObservable for removing contents", () => {
      const remove$ = JupyterContentProvider.remove(
        serverConfig,
        "/path.ipynb"
      ) as AjaxObservable;
      const request = remove$.request;
      expect(request.url).toBe("http://localhost:8888/api/contents/path.ipynb");
      expect(request.method).toBe("DELETE");
    });
  });
  describe("get", () => {
    test("creates the AjaxObservable for getting content", () => {
      const content$ = JupyterContentProvider.get(
        serverConfig,
        "/walla/walla/bingbang.ipynb"
      ) as AjaxObservable;
      const request = content$.request;
      expect(request.url).toEqual(
        expect.stringContaining(
          "http://localhost:8888/api/contents/walla/walla/bingbang.ipynb?_="
        )
      );
      expect(request.method).toBe("GET");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
    test("creates the AjaxObservable for getting content with query parameters", () => {
      const content$ = JupyterContentProvider.get(serverConfig, "/walla/walla", {
        type: "directory"
      }) as AjaxObservable;
      const request = content$.request;
      expect(request.url).toEqual(
        expect.stringContaining(
          "http://localhost:8888/api/contents/walla/walla?type=directory&_="
        )
      );
      expect(request.method).toBe("GET");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });

  describe("update", () => {
    test("creates the AjaxObservable for renaming a file", () => {
      const model = { path: "renamed/path" };
      const content$ = JupyterContentProvider.update(serverConfig, "/path/to/rename", model);
      const request = (content$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/path/to/rename"
      );
      expect(request.method).toBe("PATCH");
      expect(request.body).toEqual(model);
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });

  describe("create", () => {
    test("creates the AjaxObservable for creating content", () => {
      const model = {
        type: "notebook",
        name: "c.ipynb",
        writable: true,
        content: {},
        format: "json"
      };
      const create$ = JupyterContentProvider.create(serverConfig, "/a/b/c.ipynb", model);
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/a/b/c.ipynb"
      );
      expect(request.method).toBe("POST");
      expect(request.headers).toEqual({
        Authorization: "token secret-token",
        "Content-Type": "application/json"
      });
      expect(request.body).toEqual(model);
    });
  });

  describe("save", () => {
    test("creates the AjaxObservable for saving a file", () => {
      const model = {
        path: "save/to/this/path"
      };
      const create$ = JupyterContentProvider.save(serverConfig, "/path/to/content", model);
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/path/to/content"
      );
      expect(request.method).toBe("PUT");
      expect(request.body).toEqual(model);
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });
  describe("listCheckpoints", () => {
    test("creates the AjaxObservable for listing checkpoints of a file", () => {
      const create$ = JupyterContentProvider.listCheckpoints(
        serverConfig,
        "/path/to/content"
      );
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toEqual(
        expect.stringContaining(
          "http://localhost:8888/api/contents/path/to/content/checkpoints?_="
        )
      );
      expect(request.method).toBe("GET");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });
  describe("createCheckpoint", () => {
    test("creates the AjaxObservable for", () => {
      const create$ = JupyterContentProvider.createCheckpoint(
        serverConfig,
        "/path/to/content"
      );
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/path/to/content/checkpoints"
      );
      expect(request.method).toBe("POST");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });
  describe("deleteCheckpoint", () => {
    test("creates the AjaxObservable for", () => {
      const create$ = JupyterContentProvider.deleteCheckpoint(
        serverConfig,
        "/path/to/content",
        "id"
      );
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/path/to/content/checkpoints/id"
      );
      expect(request.method).toBe("DELETE");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });
  describe("restoreFromCheckpoint", () => {
    test("creates the AjaxObservable for", () => {
      const create$ = JupyterContentProvider.restoreFromCheckpoint(
        serverConfig,
        "/path/to/content",
        "id"
      );
      const request = (create$ as AjaxObservable).request;
      expect(request.url).toBe(
        "http://localhost:8888/api/contents/path/to/content/checkpoints/id"
      );
      expect(request.method).toBe("POST");
      expect(request.crossDomain).toBe(true);
      expect(request.responseType).toBe("json");
    });
  });
});

{'fraction_non_alphanumeric': 0.1624633431085044, 'fraction_numerical': 0.007373271889400922, 'mean_word_length': 2.820742637644046, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2881960', 'n_tokens_mistral': 3585, 'n_tokens_neox': 3508, 'n_words': 540}