Skip to content

Instantly share code, notes, and snippets.

@D7Torres
D7Torres / init.js
Created June 24, 2014 15:52
Creation of two tables witH CQL3
// This is in the init.js of our custom module. I checked that this function is being called.
// There isn't any error. But the tables are not created.
var ensureSchema = function(callback) {
Cassandra.createColumnFamilies({
'PersonalJob': 'CREATE TABLE "PersonalJob" ("revisionId" text PRIMARY KEY, "contentId" text, "jobId" text, "userId" text, "caseName" text, "xmlName" text, "fileName" text, "status" text, "units" int, "maxDuration" int, "result" text, "cost" text)',
'PersonalJobRevision': 'CREATE TABLE "PersonalJobRevision" ("jobId" text PRIMARY KEY, "revisionId" text)'
}, callback);
};
@D7Torres
D7Torres / endpoint.js
Last active December 6, 2019 12:10
Endpoint Refactor - Original
function endpoint(service, version = '') {
let protocol
let domain
if (service === 'webclient') {
protocol = __CLIENT_PROTOCOL__
domain = `${__ENV__}-${service}.${__DOMAIN__}`
if (__SERVER__) {
protocol = 'http'
} else if (__ENV__ === 'production') {
@D7Torres
D7Torres / endpoint.test.js
Last active December 6, 2019 14:42
Endpoint Refactor - Add 100% Test coverage (collapsed)
import endpoint from 'config/endpoint'
describe('endpoint.js', () => {
global.__DOMAIN__ = 'gousto.local'
let service
describe('when the service is "webclient"', () => {
beforeEach(() => {
service = 'webclient'
})
@D7Torres
D7Torres / yarn test:jest output
Created December 6, 2019 14:52
Endpoint Refactor - Test result
$ jest src/config/__tests__/endpoint.test.js
PASS src/config/__tests__/endpoint.test.js
endpoint.js
when the service is "webclient"
and being in the server side
✓ an http address with the corresponding ENV, SERVICE and DOMAIN is returned (3ms)
and not being in the server side
and the environment is production
✓ an https address with "www" and without the service, but with the DOMAIN is returned
and the environment is not production
@D7Torres
D7Torres / yarn test:jest:coverage output
Created December 6, 2019 14:59
Endpoint Refactor - Test coverage output
-------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------------|----------|----------|----------|----------|-------------------|
... | ... | ... | ... | ... | ...|
endpoint.js | 100 | 100 | 100 | 100 | |
... | ... | ... | ... | ... | ...|
-------------------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests: 12 passed, 12 total
@D7Torres
D7Torres / endpoint.js
Created December 6, 2019 15:07
Endpoint Refactor - endpoint function final result
...
function endpoint(service, version = '') {
const protocol = getProtocol(service, __SERVER__, __ENV__)
const subdomain = getSubdomain(service, __SERVER__, __ENV__)
const path = getPath(service, __SERVER__, __ENV__, version)
const port = getPort(service, __ENV__, __CLIENT__)
return `${protocol}://${subdomain}.${__DOMAIN__}${port}${path}`
}
@D7Torres
D7Torres / endpoint.js
Created December 6, 2019 16:05
Endpoint Refactor - Extracting getProtocol
const getProtocol = (service, isServerSide, environment) => {
if (service === 'webclient') {
if (isServerSide) {
return 'http'
}
return 'https'
} else {
if (environment === 'local') {
return 'http'
@D7Torres
D7Torres / truth table simple.csv
Created December 6, 2019 17:26
Endpoint Refactor - Truth table simplified
Service is Webclient Server Side Env is Local Returns
TRUE TRUE - http
TRUE FALSE - https
FALSE - TRUE http
FALSE TRUE FALSE http
FALSE FALSE FALSE https
@D7Torres
D7Torres / truth table.csv
Created December 20, 2019 14:25
Endpoint Refactor - Truth table
Service is Webclient Server Side Env is Local Returns
TRUE TRUE TRUE http
TRUE TRUE FALSE http
TRUE FALSE TRUE https
TRUE FALSE FALSE https
FALSE TRUE TRUE http
FALSE FALSE TRUE http
FALSE TRUE FALSE http
FALSE FALSE FALSE https
@D7Torres
D7Torres / endpoint.js
Last active December 20, 2019 15:29
Endpoint Refactor - Simplified getProtocol() v2
const getProtocol = (service, isServerSide, environment) => {
if (isServerSide) {
return 'http'
}
if (service === 'webclient') {
return 'https'
}
if (service !== 'webclient' && environment !== 'local') {