Skip to content

Instantly share code, notes, and snippets.

View mutaimwiti's full-sized avatar
🕵️‍♂️
JavaScripting

Mutai Mwiti mutaimwiti

🕵️‍♂️
JavaScripting
View GitHub Profile
@mutaimwiti
mutaimwiti / huawei_e303_api_device
Created August 26, 2016 08:03 — forked from manuel-rabade/huawei_e303_api_device
API del modem Huawei E303
$ curl http://192.168.1.1/api/device/information
<?xml version="1.0" encoding="UTF-8"?>
<response>
<DeviceName>E303</DeviceName>
<SerialNumber>K3XBYAxxxxxxxxxx</SerialNumber>
<Imei>xxxxxxxxxxxxxxx</Imei>
<Imsi>xxxxxxxxxxxxxxx</Imsi>
<Iccid>xxxxxxxxxxxxxxxxxxxx</Iccid>
<Msisdn></Msisdn>
<HardwareVersion>CH2E303SM</HardwareVersion>
@mutaimwiti
mutaimwiti / test_login.py
Last active September 19, 2018 13:02
Example Python test
from unittest import TestCase
from rest_framework import status
from rest_framework.test import APIClient
class BaseTestCase(TestCase):
def setUp(self):
self.client = APIClient()
def post_login(self, username='johndoe', password='P@$$word'):
@mutaimwiti
mutaimwiti / app.js
Created January 22, 2019 14:46 — forked from joshnuss/app.js
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./permission"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@mutaimwiti
mutaimwiti / Loading CMS data.md
Last active March 5, 2019 10:26
Updates to load cms data
  • The dots(.) on the file names represent the directory hierarchy e.g. js.cms.[your_module].js represents js/cms/[your_module].js.
  • REPLACE the current js/utils.js file with the one on this gist. The changes on this file allow for synchronization of cms data loading for your module.
  • Follow the same naming convection for your module scripts. If your script belongs to a broad module create a subdirectory for the module e.g. js/cms/repository/documents.js
  • ENSURE you place the link to your script on the section to that is loaded by jquery. e.g. documents.js is imported inside documents.html of resources.
  • CREATE js/cms/utils.js and add the content on this gist. This will prevent multiple
@mutaimwiti
mutaimwiti / article.spec.js
Last active November 18, 2019 16:05
supertest-scenario-1
const request = require('supertest');
const request = supertest(app);
describe('Articles', function () {
it('should allow users to list all articles', function (done) {
request.get('/articles').expect(200, done)
});
it('should allow users to get one article', function (done) {
@mutaimwiti
mutaimwiti / article.spec.js
Created November 15, 2019 10:43
supertest-scenario-2
const request = require('supertest');
describe('Articles', function () {
it('should allow users to list all articles', function (done) {
request(app).get('/articles').expect(200, done)
});
it('should allow users to get one article', function (done) {
request(app).get('/articles/2').expect(200, done)
});
@mutaimwiti
mutaimwiti / article.spec.js
Created November 15, 2019 10:54
supertest-scenario-3
const request = require('supertest');
const request = supertest(app);
describe('Articles', function () {
it('should allow users to list all articles', function (done) {
request
.get('/articles')
.set('authorization', generateAuthToken())
.expect(200, done)
@mutaimwiti
mutaimwiti / article.spec.js
Last active November 27, 2019 08:08
Using wrapper es6
// test/article.spec.js
import app from './testUtils/app';
describe('Articles', () => {
describe('GET', () => {
it('should not allow unauthenticated users to list all articles', async () => {
const res = await app.get('/articles');
expect(res.status).toBe(401);
@mutaimwiti
mutaimwiti / article.spec.js
Last active November 27, 2019 08:10
Using wrapper es5
// test/article.spec.js
var app = require('./testUtils/app');
describe('Articles', function() {
describe('GET', function() {
it('should not allow unauthenticated users to list all articles', function(done) {
app.get('/articles').expect(401, done);
});
it('should allow authenticated users to list all articles', function(done) {
@mutaimwiti
mutaimwiti / app.js
Last active November 25, 2019 18:13
Wrapper es5
// test/testUtils/app.js
var supertest = require('supertest');
var appDef = require('../../src/app');
var User = require('../../src/models').User;
var generateAuthToken = require('../../src/utils').generateAuthToken;
var app = {
client: supertest(appDef),