1 | import {should} from 'chai';
|
2 | import {Core, Kore} from "@kirinnee/core";
|
3 | import {EmailValid, KeyValid, NameValid} from "../src/push";
|
4 |
|
5 | should();
|
6 | let core: Core = new Kore();
|
7 | core.ExtendPrimitives();
|
8 |
|
9 | describe("Push Validation", () => {
|
10 | describe("email", () => {
|
11 | it("should allow email format", () => {
|
12 | EmailValid("ernest@gmail.com").should.be.true;
|
13 | });
|
14 |
|
15 | it("should return false if empty before @ sign", () => {
|
16 | EmailValid("@gmail.com").should.be.false;
|
17 | });
|
18 |
|
19 | it("should return false if no @ sign is found", () => {
|
20 | EmailValid("gmail.com").should.be.false;
|
21 | });
|
22 |
|
23 | it("should return false if nothing is behind @ sign", () => {
|
24 | EmailValid("ernest@").should.be.false;
|
25 | });
|
26 | });
|
27 |
|
28 | describe("key", () => {
|
29 | it("should allow values that are alphanumeric lower and spaces", () => {
|
30 | KeyValid('a').should.be.true;
|
31 | KeyValid('azurekey').should.be.true;
|
32 | KeyValid('azure_key').should.be.true;
|
33 | KeyValid('azure_key_11').should.be.true;
|
34 | });
|
35 |
|
36 | it("should not allow it to start with numeric value", () => {
|
37 | KeyValid('1').should.be.false;
|
38 | KeyValid('2key').should.be.false;
|
39 | });
|
40 |
|
41 | it('should not allow special characters', () => {
|
42 | KeyValid('azure*key').should.be.false;
|
43 | KeyValid('azurekey!').should.be.false;
|
44 | });
|
45 |
|
46 | it('should not allow - ', () => {
|
47 | KeyValid('azure-key').should.be.false;
|
48 | KeyValid('azure-1').should.be.false;
|
49 | });
|
50 |
|
51 | it('should not allow upper-case', () => {
|
52 | KeyValid('Azure_key').should.be.false;
|
53 | KeyValid('azureKey').should.be.false;
|
54 | });
|
55 | });
|
56 |
|
57 | describe("name", () => {
|
58 | it('should allow alphabet, numbers, spaces, dash, underscore and spaces', function () {
|
59 | NameValid("Some Cool Name").should.be.true;
|
60 | NameValid("Very Cold Name").should.be.true;
|
61 | NameValid("under_score_case").should.be.true;
|
62 | NameValid("Dash-case").should.be.true;
|
63 | NameValid("with-1-2-numbers").should.be.true;
|
64 | });
|
65 |
|
66 | it("should not start with number", () => {
|
67 | NameValid('1-starts-with-number').should.be.false;
|
68 | NameValid('1key').should.be.false;
|
69 | });
|
70 |
|
71 | it('should not contain special character', () => {
|
72 | NameValid('Kira*').should.be.false;
|
73 | NameValid('Hey!').should.be.false;
|
74 | NameValid('comma,comma').should.be.false;
|
75 | });
|
76 |
|
77 | it('should not allow name 2 character or shorter', () => {
|
78 | NameValid('hi').should.be.false;
|
79 | NameValid('Ab').should.be.false;
|
80 | });
|
81 | });
|
82 | });
|
83 |
|