summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/test/test-jetpack-id.js
blob: 99479e32d3f7a7afa18c557ae5f86a5a80333609 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

var getID = require("jetpack-id/index");

exports["test Returns GUID when `id` GUID"] = assert => {
  var guid = "{8490ae4f-93bc-13af-80b3-39adf9e7b243}";
  assert.equal(getID({ id: guid }), guid);
};

exports["test Returns domain id when `id` domain id"] = assert => {
  var id = "my-addon@jetpack";
  assert.equal(getID({ id: id }), id);
};

exports["test allows underscores in name"] = assert => {
  var name = "my_addon";
  assert.equal(getID({ name: name }), `@${name}`);
};

exports["test allows underscores in id"] = assert => {
  var id = "my_addon@jetpack";
  assert.equal(getID({ id: id }), id);
};

exports["test Returns valid name when `name` exists"] = assert => {
  var id = "my-addon";
  assert.equal(getID({ name: id }), `@${id}`);
};


exports["test Returns null when `id` and `name` do not exist"] = assert => {
  assert.equal(getID({}), null)
}

exports["test Returns null when no object passed in"] = assert => {
  assert.equal(getID(), null)
}

exports["test Returns null when `id` exists but not GUID/domain"] = assert => {
  var id = "my-addon";
  assert.equal(getID({ id: id }), null);
}

exports["test Returns null when `id` contains multiple @"] = assert => {
  assert.equal(getID({ id: "my@addon@yeah" }), null);
};

exports["test Returns null when `id` or `name` specified in domain format but has invalid characters"] = assert => {
  [" ", "!", "/", "$", "  ", "~", "("].forEach(sym => {
    assert.equal(getID({ id: "my" + sym + "addon@domain" }), null);
    assert.equal(getID({ name: "my" + sym + "addon" }), null);
  });
};

exports["test Returns null, does not crash, when providing non-string properties for `name` and `id`"] = assert => {
  assert.equal(getID({ id: 5 }), null);
  assert.equal(getID({ name: 5 }), null);
  assert.equal(getID({ name: {} }), null);
};

require("sdk/test").run(exports);