Change order of repositoryName and pluginName

This commit is contained in:
Dandelion Mané 2018-02-28 17:46:17 -08:00
parent 58ad1eb635
commit 9dc9d5e4f3
2 changed files with 13 additions and 13 deletions

View File

@ -27,19 +27,19 @@ export type Graph = {
};
export function addressToString(address: Address) {
if (address.pluginName.includes("$")) {
const escaped = JSON.stringify(address.pluginName);
throw new Error(`address.pluginName must not include "\$": ${escaped}`);
}
if (address.repositoryName.includes("$")) {
const escaped = JSON.stringify(address.repositoryName);
throw new Error(`address.repositoryName must not include "\$": ${escaped}`);
}
if (address.pluginName.includes("$")) {
const escaped = JSON.stringify(address.pluginName);
throw new Error(`address.pluginName must not include "\$": ${escaped}`);
}
if (address.id.includes("$")) {
const escaped = JSON.stringify(address.id);
throw new Error(`address.id must not include "\$": ${escaped}`);
}
return `${address.pluginName}\$${address.repositoryName}\$${address.id}`;
return `${address.repositoryName}\$${address.pluginName}\$${address.id}`;
}
export function stringToAddress(string: string) {
@ -49,8 +49,8 @@ export function stringToAddress(string: string) {
throw new Error(`Input should have exactly two \$s: ${escaped}`);
}
return {
pluginName: parts[0],
repositoryName: parts[1],
repositoryName: parts[0],
pluginName: parts[1],
id: parts[2],
};
}

View File

@ -3,13 +3,13 @@ import {addressToString, stringToAddress} from "./graph";
describe("graph", () => {
describe("addressToString", () => {
const makeSimpleAddress = () => ({
pluginName: "widgets",
repositoryName: "megacorp/megawidget",
pluginName: "widgets",
id: "issue#123",
});
it("stringifies a simple Address", () => {
const input = makeSimpleAddress();
const expected = "widgets$megacorp/megawidget$issue#123";
const expected = "megacorp/megawidget$widgets$issue#123";
expect(addressToString(input)).toEqual(expected);
});
function expectRejection(attribute, value) {
@ -30,10 +30,10 @@ describe("graph", () => {
describe("stringToAddress", () => {
it("parses a simple Address-string", () => {
const input = "widgets$megacorp/megawidget$issue#123";
const input = "megacorp/megawidget$widgets$issue#123";
const expected = {
pluginName: "widgets",
repositoryName: "megacorp/megawidget",
pluginName: "widgets",
id: "issue#123",
};
expect(stringToAddress(input)).toEqual(expected);
@ -51,11 +51,11 @@ describe("graph", () => {
const examples = () => [
{
object: {
pluginName: "widgets",
repositoryName: "megacorp/megawidget",
pluginName: "widgets",
id: "issue#123",
},
string: "widgets$megacorp/megawidget$issue#123",
string: "megacorp/megawidget$widgets$issue#123",
},
];
examples().forEach((example, index) => {