1 | "use strict";
|
2 | import Promise from "bluebird";
|
3 | import { expect } from "chai";
|
4 | import fsPath from "path";
|
5 | import appSync from "../src/main";
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | describe("api (module)", () => {
|
11 | let api;
|
12 | beforeEach(() => {
|
13 | Promise.coroutine(function*() {
|
14 | api = yield appSync();
|
15 | }).call(this);
|
16 | });
|
17 |
|
18 | describe("init", function() {
|
19 | it("initializes with default values", () => {
|
20 | expect(api.userAgent).to.equal("app-syncer");
|
21 | });
|
22 |
|
23 | it("has default values", () => {
|
24 | expect(api.apps).to.eql([]);
|
25 | expect(api.targetFolder).to.equal("./.build");
|
26 | });
|
27 | });
|
28 |
|
29 |
|
30 | describe("add", function() {
|
31 | it("has no apps", () => {
|
32 | expect(api.apps).to.eql([]);
|
33 | });
|
34 |
|
35 | it("adds an app (root of repo)", () => {
|
36 | api.add("my-app", "philcockfield/app-sync", "*/foo");
|
37 | const app = api.apps[0];
|
38 | expect(app.id).to.equal("my-app");
|
39 | expect(app.repo.name).to.equal("philcockfield/app-sync");
|
40 | expect(app.localFolder).to.equal(fsPath.resolve("./.build/my-app"));
|
41 | expect(app.route.domain).to.equal("*");
|
42 | expect(app.route.path).to.equal("foo/");
|
43 | });
|
44 |
|
45 | it("adds an app with a path to a sub-folder within the repo", () => {
|
46 | api.add("my-app", "philcockfield/app-sync/example/app-1", "*/foo");
|
47 | const app = api.apps[0];
|
48 | expect(app.id).to.equal("my-app");
|
49 | expect(app.repo.name).to.equal("philcockfield/app-sync");
|
50 | expect(app.localFolder).to.equal(fsPath.resolve("./.build/my-app"));
|
51 | });
|
52 |
|
53 | it("adds an app with default values", () => {
|
54 | api.add("my-app", "philcockfield/app-sync/example/app-1", "*/foo");
|
55 | const app = api.apps[0];
|
56 | expect(app.branch).to.equal("master");
|
57 | });
|
58 |
|
59 | it("throws if the 'id' 'repo' or 'route' are not specified", () => {
|
60 | expect(() => api.add(undefined, "user/my-repo", "*/foo")).to.throw();
|
61 | expect(() => api.add("name", null, "*/foo")).to.throw();
|
62 | expect(() => api.add("name", "user/repo")).to.throw();
|
63 | });
|
64 |
|
65 | it("throws if the repo is not two parts (username/repo-name)", () => {
|
66 | expect(() => api.add("my-app", "fail", "*/foo")).to.throw();
|
67 | });
|
68 |
|
69 | it("throws if a 'id' is repeated", () => {
|
70 | api.add("my-app", "user/my-repo-1", "*/foo-1");
|
71 | let fn = () => {
|
72 | api.add("my-app", "user/my-repo-2", "*/foo-2");
|
73 | };
|
74 | expect(fn).to.throw();
|
75 | });
|
76 |
|
77 |
|
78 | it("throws if a route is repeated", () => {
|
79 | api.add("my-app-1", "user/my-repo-1", "*/foo");
|
80 | let fn = () => {
|
81 | api.add("my-app-2", "user/my-repo-2", "*/foo");
|
82 | };
|
83 | expect(fn).to.throw();
|
84 | });
|
85 |
|
86 |
|
87 | it("auto-assigns port numbers", () => {
|
88 | api.add("my-app-1", "user/my-repo", "*/foo-1");
|
89 | api.add("my-app-2", "user/my-repo", "*/foo-2");
|
90 | expect(api.apps[0].port).to.equal(5000);
|
91 | expect(api.apps[1].port).to.equal(5001);
|
92 | });
|
93 | });
|
94 |
|
95 | describe("remove", function() {
|
96 | it("removes the specified app", () => {
|
97 | api.add("my-app-1", "user/my-repo", "*/foo-1");
|
98 | return api.remove("my-app-1")
|
99 | .then(result => {
|
100 | expect(api.apps.length).to.equal(0);
|
101 | });
|
102 | });
|
103 | });
|
104 | });
|