Add unit tests for projectFromJSON's upgrade support (#1519)

This commit is contained in:
Robin van Boven 2020-01-03 14:57:46 +01:00 committed by GitHub
parent fb16530b8f
commit b7b93d2a8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ import {
} from "./project";
import {makeRepoId} from "./repoId";
import {toCompat} from "../util/compat";
describe("core/project", () => {
const foobar = deepFreeze(makeRepoId("foo", "bar"));
@ -41,6 +42,58 @@ describe("core/project", () => {
check(p1);
check(p2);
});
it("should upgrade from 0.3.0 formatting", () => {
// Given
const body = {
id: "example-030",
repoIds: [foobar, foozod],
discourseServer: {
serverUrl: "https://example.com",
apiUsername: "hello-test",
},
identities: [],
};
const compat = toCompat(
{type: "sourcecred/project", version: "0.3.0"},
body
);
// When
const project = projectFromJSON(compat);
// Then
expect(project).toEqual({
...body,
// It should strip the apiUsername field, keeping just serverUrl.
discourseServer: {serverUrl: "https://example.com"},
});
});
it("should upgrade from 0.3.1 formatting", () => {
// Given
const body = {
id: "example-031",
repoIds: [foobar, foozod],
discourseServer: {
serverUrl: "https://example.com",
apiUsername: "hello-test",
},
identities: [],
};
const compat = toCompat(
{type: "sourcecred/project", version: "0.3.1"},
body
);
// When
const project = projectFromJSON(compat);
// Then
expect(project).toEqual({
...body,
// It should strip the apiUsername field, keeping just serverUrl.
discourseServer: {serverUrl: "https://example.com"},
});
});
});
describe("encodeProjectId", () => {
it("is a base64-url encoded id", () => {