Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a testing framework #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions js/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function validateExtension(file) {
const fileName = file.name;
const fileExtension =fileName.substr(fileName.lastIndexOf('.')).toLowerCase();

const _validFileExtensions = [".jpg", ".jpeg", ".bmp", ".gif", ".png"];

return _validFileExtensions.find((ext) => fileExtension === ext) || null;
}

module.exports = {validateExtension};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "HTML5 inApp support chat using your own firebase account",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "./node_modules/mocha/bin/mocha"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -34,6 +34,7 @@
"homepage": "https://github.com/CodingCarlos/inapp-support#readme",
"devDependencies": {
"browser-sync": "^2.18.2",
"chai": "^3.5.0",
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.1",
Expand All @@ -42,6 +43,7 @@
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^1.9.1",
"gulp-uglify": "^2.0.0",
"mocha": "^3.2.0",
"run-sequence": "^1.2.2"
}
}
56 changes: 56 additions & 0 deletions test/chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const expect = require('chai').expect;

const utils = require('../js/utils');

describe('Chat inapp', () => {
describe('validates file extensions', () => {
it('jpg is a valid extension', () => {
const file = {name:'chat.jpg'};

const ext = utils.validateExtension(file);

expect(ext).to.equal('.jpg');
});

it('png is a valid extension', () => {
const file = {name:'chat.png'};

const ext = utils.validateExtension(file);

expect(ext).to.equal('.png');
});

it('js is NOT a valid extension', () => {
const file = {name:'chat.js'};

const ext = utils.validateExtension(file);

expect(ext).to.be.null;
});

it('PNG is a valid extension', () => {
const file = {name:'chat.PNG'};

const ext = utils.validateExtension(file);

expect(ext).to.equal('.png');
});

it('no extension is NOT valid', () => {
const file = {name:'chat'};

const ext = utils.validateExtension(file);

expect(ext).to.be.null;
});

it('just extension is NOT valid', () => {
const file = {name:'jpg'};

const ext = utils.validateExtension(file);

expect(ext).to.be.null;
});

});
});