mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
refactor: fix code review suggestions
This commit is contained in:
parent
3c157a221a
commit
e0d3223968
11 changed files with 260 additions and 261 deletions
10
src/lib/bootstrap.js
vendored
10
src/lib/bootstrap.js
vendored
|
@ -1,6 +1,4 @@
|
|||
import isFunction from 'lodash/isFunction';
|
||||
import assign from 'lodash/assign';
|
||||
import isObject from 'lodash/isObject';
|
||||
import {assign, isObject, isFunction} from 'lodash';
|
||||
import Path from 'path';
|
||||
import URL from 'url';
|
||||
import fs from 'fs';
|
||||
|
@ -36,16 +34,16 @@ function getListListenAddresses(argListen, configListen) {
|
|||
addresses = ['4873'];
|
||||
}
|
||||
addresses = addresses.map(function(addr) {
|
||||
const parsed_addr = Utils.parse_address(addr);
|
||||
const parsedAddr = Utils.parse_address(addr);
|
||||
|
||||
if (!parsed_addr) {
|
||||
if (!parsedAddr) {
|
||||
logger.logger.warn({addr: addr},
|
||||
'invalid address - @{addr}, we expect a port (e.g. "4873"),'
|
||||
+ ' host:port (e.g. "localhost:4873") or full url'
|
||||
+ ' (e.g. "http://localhost:4873/")');
|
||||
}
|
||||
|
||||
return parsed_addr;
|
||||
return parsedAddr;
|
||||
}).filter(Boolean);
|
||||
|
||||
return addresses;
|
||||
|
|
|
@ -10,7 +10,7 @@ const CONFIG_FILE = 'config.yaml';
|
|||
const XDG = 'xdg';
|
||||
const WIN = 'win';
|
||||
const WIN32 = 'win32';
|
||||
const pkgJson = require('../../package.json');
|
||||
const pkgJSON = require('../../package.json');
|
||||
|
||||
/**
|
||||
* Find and get the first config file that match.
|
||||
|
@ -63,7 +63,7 @@ function updateStorageLinks(configLocation, defaultConfig) {
|
|||
// If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.
|
||||
let dataDir = process.env.XDG_DATA_HOME || Path.join(process.env.HOME, '.local', 'share');
|
||||
if (folder_exists(dataDir)) {
|
||||
dataDir = Path.resolve(Path.join(dataDir, pkgJson.name, 'storage'));
|
||||
dataDir = Path.resolve(Path.join(dataDir, pkgJSON.name, 'storage'));
|
||||
return defaultConfig.replace(/^storage: .\/storage$/m, `storage: ${dataDir}`);
|
||||
} else {
|
||||
return defaultConfig;
|
||||
|
@ -71,16 +71,16 @@ function updateStorageLinks(configLocation, defaultConfig) {
|
|||
}
|
||||
|
||||
function getConfigPaths() {
|
||||
return _.filter([getXDGDirectory(), getWindowsDirectory(), getRelativeDefaultDirectory(), getOldDirectory()]);
|
||||
return [getXDGDirectory(), getWindowsDirectory(), getRelativeDefaultDirectory(), getOldDirectory()].filter((path) => !!path);
|
||||
}
|
||||
|
||||
const getXDGDirectory = () => {
|
||||
const xdgConfig = getXDGHome() ||
|
||||
const XDGConfig = getXDGHome() ||
|
||||
process.env.HOME && Path.join(process.env.HOME, '.config');
|
||||
|
||||
if (xdgConfig && folder_exists(xdgConfig)) {
|
||||
if (XDGConfig && folder_exists(XDGConfig)) {
|
||||
return {
|
||||
path: Path.join(xdgConfig, pkgJson.name, CONFIG_FILE),
|
||||
path: Path.join(XDGConfig, pkgJSON.name, CONFIG_FILE),
|
||||
type: XDG,
|
||||
};
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ const getXDGHome = () => process.env.XDG_CONFIG_HOME;
|
|||
const getWindowsDirectory = () => {
|
||||
if (process.platform === WIN32 && process.env.APPDATA && folder_exists(process.env.APPDATA)) {
|
||||
return {
|
||||
path: Path.resolve(Path.join(process.env.APPDATA, pkgJson.name, CONFIG_FILE)),
|
||||
path: Path.resolve(Path.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),
|
||||
type: WIN,
|
||||
};
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ const getWindowsDirectory = () => {
|
|||
|
||||
const getRelativeDefaultDirectory = () => {
|
||||
return {
|
||||
path: Path.resolve(Path.join('.', pkgJson.name, CONFIG_FILE)),
|
||||
path: Path.resolve(Path.join('.', pkgJSON.name, CONFIG_FILE)),
|
||||
type: 'def',
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// @flow
|
||||
|
||||
/* eslint prefer-rest-params: 0 */
|
||||
/* eslint spaced-comment: 0 */
|
||||
|
||||
import assert from 'assert';
|
||||
import Crypto from 'crypto';
|
||||
|
@ -24,10 +23,12 @@ import type {
|
|||
DistFile,
|
||||
Callback,
|
||||
Logger,
|
||||
Utils} from '@verdaccio/types';
|
||||
import type {
|
||||
ILocalFS,
|
||||
ILocalData} from '@verdaccio/local-storage';
|
||||
Utils,
|
||||
} from '@verdaccio/types';
|
||||
import type {
|
||||
ILocalFS,
|
||||
ILocalData,
|
||||
} from '@verdaccio/local-storage';
|
||||
|
||||
const pkgFileName = 'package.json';
|
||||
const fileExist = 'EEXISTS';
|
||||
|
@ -181,6 +182,7 @@ class Storage implements IStorage {
|
|||
url: version.dist.tarball,
|
||||
sha: version.dist.shasum,
|
||||
};
|
||||
/* eslint spaced-comment: 0 */
|
||||
//$FlowFixMe
|
||||
const upLink: string = version[Symbol.for('__verdaccio_uplink')];
|
||||
|
||||
|
|
|
@ -371,7 +371,7 @@ function folder_exists(path) {
|
|||
* @param {String} path
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function file_exists(path) {
|
||||
function fileExists(path) {
|
||||
try {
|
||||
const stat = fs.statSync(path);
|
||||
return stat.isFile();
|
||||
|
@ -381,7 +381,7 @@ function file_exists(path) {
|
|||
}
|
||||
|
||||
module.exports.folder_exists = folder_exists;
|
||||
module.exports.file_exists = file_exists;
|
||||
module.exports.file_exists = fileExists;
|
||||
module.exports.parseInterval = parseInterval;
|
||||
module.exports.semver_sort = semverSort;
|
||||
module.exports.parse_address = parse_address;
|
||||
|
|
|
@ -34,83 +34,83 @@ import upLinkCache from './uplink.cache.spec';
|
|||
import upLinkAuth from './uplink.auth.spec';
|
||||
|
||||
describe('functional test verdaccio', function() {
|
||||
const EXPRESS_PORT = 55550;
|
||||
const SILENCE_LOG = !process.env.VERDACCIO_DEBUG;
|
||||
const processRunning = [];
|
||||
const config1 = new VerdaccioConfig(
|
||||
'./store/test-storage',
|
||||
'./store/config-1.yaml',
|
||||
'http://localhost:55551/');
|
||||
const config2 = new VerdaccioConfig(
|
||||
'./store/test-storage2',
|
||||
'./store/config-2.yaml',
|
||||
'http://localhost:55552/');
|
||||
const config3 = new VerdaccioConfig(
|
||||
'./store/test-storage3',
|
||||
'./store/config-3.yaml',
|
||||
'http://localhost:55553/');
|
||||
const server1: IServerBridge = new Server(config1.domainPath);
|
||||
const server2: IServerBridge = new Server(config2.domainPath);
|
||||
const server3: IServerBridge = new Server(config3.domainPath);
|
||||
const process1: IServerProcess = new VerdaccioProcess(config1, server1, SILENCE_LOG);
|
||||
const process2: IServerProcess = new VerdaccioProcess(config2, server2, SILENCE_LOG);
|
||||
const process3: IServerProcess = new VerdaccioProcess(config3, server3, SILENCE_LOG);
|
||||
const express: any = new ExpressServer();
|
||||
const EXPRESS_PORT = 55550;
|
||||
const SILENCE_LOG = !process.env.VERDACCIO_DEBUG;
|
||||
const processRunning = [];
|
||||
const config1 = new VerdaccioConfig(
|
||||
'./store/test-storage',
|
||||
'./store/config-1.yaml',
|
||||
'http://localhost:55551/');
|
||||
const config2 = new VerdaccioConfig(
|
||||
'./store/test-storage2',
|
||||
'./store/config-2.yaml',
|
||||
'http://localhost:55552/');
|
||||
const config3 = new VerdaccioConfig(
|
||||
'./store/test-storage3',
|
||||
'./store/config-3.yaml',
|
||||
'http://localhost:55553/');
|
||||
const server1: IServerBridge = new Server(config1.domainPath);
|
||||
const server2: IServerBridge = new Server(config2.domainPath);
|
||||
const server3: IServerBridge = new Server(config3.domainPath);
|
||||
const process1: IServerProcess = new VerdaccioProcess(config1, server1, SILENCE_LOG);
|
||||
const process2: IServerProcess = new VerdaccioProcess(config2, server2, SILENCE_LOG);
|
||||
const process3: IServerProcess = new VerdaccioProcess(config3, server3, SILENCE_LOG);
|
||||
const express: any = new ExpressServer();
|
||||
|
||||
beforeAll((done) => {
|
||||
Promise.all([
|
||||
process1.init(),
|
||||
process2.init(),
|
||||
process3.init()]).then((forks) => {
|
||||
_.map(forks, (fork) => {
|
||||
processRunning.push(fork[0]);
|
||||
});
|
||||
express.start(EXPRESS_PORT).then((app) =>{
|
||||
done();
|
||||
}, (err) => {
|
||||
done(err);
|
||||
});
|
||||
}).catch((error) => {
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
beforeAll((done) => {
|
||||
Promise.all([
|
||||
process1.init(),
|
||||
process2.init(),
|
||||
process3.init()]).then((forks) => {
|
||||
_.map(forks, (fork) => {
|
||||
processRunning.push(fork[0]);
|
||||
});
|
||||
express.start(EXPRESS_PORT).then((app) =>{
|
||||
done();
|
||||
}, (err) => {
|
||||
done(err);
|
||||
});
|
||||
}).catch((error) => {
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
_.map(processRunning, (fork) => {
|
||||
fork.stop();
|
||||
});
|
||||
express.server.close();
|
||||
});
|
||||
afterAll(() => {
|
||||
_.map(processRunning, (fork) => {
|
||||
fork.stop();
|
||||
});
|
||||
express.server.close();
|
||||
});
|
||||
|
||||
// list of test
|
||||
// note: order of the following calls is important
|
||||
packageAccess(server1);
|
||||
basic(server1, server2);
|
||||
gh29(server1, server2);
|
||||
tags(server1, express.app);
|
||||
packageGzip(server1, express.app);
|
||||
incomplete(server1, express.app);
|
||||
mirror(server1, server2);
|
||||
preserveTags(server1, server2, express.app);
|
||||
readme(server1, server2);
|
||||
nullstorage(server1, server2);
|
||||
race(server1);
|
||||
racycrash(server1, express.app);
|
||||
packageScoped(server1, server2);
|
||||
security(server1);
|
||||
addtag(server1);
|
||||
pluginsAuth(server2);
|
||||
notify(express.app);
|
||||
// list of test
|
||||
// note: order of the following calls is important
|
||||
packageAccess(server1);
|
||||
basic(server1, server2);
|
||||
gh29(server1, server2);
|
||||
tags(server1, express.app);
|
||||
packageGzip(server1, express.app);
|
||||
incomplete(server1, express.app);
|
||||
mirror(server1, server2);
|
||||
preserveTags(server1, server2, express.app);
|
||||
readme(server1, server2);
|
||||
nullstorage(server1, server2);
|
||||
race(server1);
|
||||
racycrash(server1, express.app);
|
||||
packageScoped(server1, server2);
|
||||
security(server1);
|
||||
addtag(server1);
|
||||
pluginsAuth(server2);
|
||||
notify(express.app);
|
||||
// requires packages published to server1/server2
|
||||
upLinkCache(server1, server2, server3);
|
||||
upLinkAuth();
|
||||
adduser(server1);
|
||||
logout(server1);
|
||||
upLinkCache(server1, server2, server3);
|
||||
upLinkAuth();
|
||||
adduser(server1);
|
||||
logout(server1);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', function(err) {
|
||||
console.error("unhandledRejection", err);
|
||||
process.nextTick(function() {
|
||||
throw err;
|
||||
});
|
||||
console.error("unhandledRejection", err);
|
||||
process.nextTick(function() {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -23,7 +23,7 @@ export default class Server implements IServerBridge {
|
|||
request(options: any): any {
|
||||
// console.log("--->$$$$ REQUEST", options);
|
||||
assert(options.uri);
|
||||
const headers: any = options.headers || {};
|
||||
const headers = options.headers || {};
|
||||
|
||||
headers.accept = headers.accept || 'application/json';
|
||||
headers['user-agent'] = headers['user-agent'] || this.userAgent;
|
||||
|
|
|
@ -7,67 +7,67 @@ import type {IVerdaccioConfig, IServerBridge, IServerProcess} from './types';
|
|||
|
||||
export default class VerdaccioProcess implements IServerProcess {
|
||||
|
||||
bridge: IServerBridge;
|
||||
config: IVerdaccioConfig;
|
||||
childFork: any;
|
||||
silence: boolean;
|
||||
bridge: IServerBridge;
|
||||
config: IVerdaccioConfig;
|
||||
childFork: any;
|
||||
silence: boolean;
|
||||
|
||||
constructor(config: IVerdaccioConfig, bridge: IServerBridge, silence: boolean = true) {
|
||||
this.config = config;
|
||||
this.bridge = bridge;
|
||||
this.silence = silence;
|
||||
}
|
||||
constructor(config: IVerdaccioConfig, bridge: IServerBridge, silence: boolean = true) {
|
||||
this.config = config;
|
||||
this.bridge = bridge;
|
||||
this.silence = silence;
|
||||
}
|
||||
|
||||
init(): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const verdaccioRegisterWrap: string = path.join(__dirname, '../../../bin/verdaccio');
|
||||
const storageDir: string = path.join(__dirname, `/../${this.config.storagePath}`);
|
||||
const configPath: string = path.join(__dirname, '../', this.config.configPath);
|
||||
init(): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const verdaccioRegisterWrap: string = path.join(__dirname, '../../../bin/verdaccio');
|
||||
const storageDir: string = path.join(__dirname, `/../${this.config.storagePath}`);
|
||||
const configPath: string = path.join(__dirname, '../', this.config.configPath);
|
||||
|
||||
rimRaf(storageDir, (err) => {
|
||||
if (_.isNil(err) === false) {
|
||||
reject(err);
|
||||
}
|
||||
rimRaf(storageDir, (err) => {
|
||||
if (_.isNil(err) === false) {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
this.childFork = fork(verdaccioRegisterWrap,
|
||||
['-c', configPath],
|
||||
{
|
||||
silent: this.silence
|
||||
}
|
||||
);
|
||||
this.childFork = fork(verdaccioRegisterWrap,
|
||||
['-c', configPath],
|
||||
{
|
||||
silent: this.silence
|
||||
}
|
||||
);
|
||||
|
||||
this.childFork.on('message', (msg) => {
|
||||
if ('verdaccio_started' in msg) {
|
||||
this.bridge.debug().status(200).then((body) => {
|
||||
this.bridge.auth('test', 'test')
|
||||
.status(201)
|
||||
.body_ok(/'test'/)
|
||||
.then(() => {
|
||||
resolve([this, body.pid]);
|
||||
}, reject)
|
||||
}, reject);
|
||||
}
|
||||
});
|
||||
this.childFork.on('message', (msg) => {
|
||||
if ('verdaccio_started' in msg) {
|
||||
this.bridge.debug().status(200).then((body) => {
|
||||
this.bridge.auth('test', 'test')
|
||||
.status(201)
|
||||
.body_ok(/'test'/)
|
||||
.then(() => {
|
||||
resolve([this, body.pid]);
|
||||
}, reject)
|
||||
}, reject);
|
||||
}
|
||||
});
|
||||
|
||||
this.childFork.on('error', function(err) {
|
||||
reject(err);
|
||||
});
|
||||
this.childFork.on('error', function(err) {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
this.childFork.on('disconnect', function(err) {
|
||||
reject(err);
|
||||
});
|
||||
this.childFork.on('disconnect', function(err) {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
this.childFork.on('exit', function(err) {
|
||||
reject(err);
|
||||
});
|
||||
this.childFork.on('exit', function(err) {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
return this.childFork.kill('SIGINT');
|
||||
}
|
||||
stop(): void {
|
||||
return this.childFork.kill('SIGINT');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -3,24 +3,24 @@ import express from 'express';
|
|||
import bodyParser from 'body-parser';
|
||||
|
||||
export default class ExpressServer {
|
||||
app: any;
|
||||
server: any;
|
||||
app: any;
|
||||
server: any;
|
||||
|
||||
constructor() {
|
||||
this.app = express();
|
||||
this.server;
|
||||
}
|
||||
constructor() {
|
||||
this.app = express();
|
||||
this.server;
|
||||
}
|
||||
|
||||
start(port: number): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.app.use(bodyParser.json());
|
||||
this.app.use(bodyParser.urlencoded({
|
||||
extended: true
|
||||
}));
|
||||
start(port: number): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.app.use(bodyParser.json());
|
||||
this.app.use(bodyParser.urlencoded({
|
||||
extended: true
|
||||
}));
|
||||
|
||||
this.server = this.app.listen(port, function starExpressServer() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
this.server = this.app.listen(port, function starExpressServer() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,52 +1,52 @@
|
|||
// @flow
|
||||
|
||||
export interface IVerdaccioConfig {
|
||||
storagePath: string;
|
||||
configPath: string;
|
||||
domainPath: string;
|
||||
storagePath: string;
|
||||
configPath: string;
|
||||
domainPath: string;
|
||||
}
|
||||
|
||||
export interface IRequestPromise {
|
||||
status(reason: any): any;
|
||||
body_ok(reason: any): any;
|
||||
body_error(reason: any): any;
|
||||
request(reason: any): any;
|
||||
response(reason: any): any;
|
||||
send(reason: any): any;
|
||||
status(reason: any): any;
|
||||
body_ok(reason: any): any;
|
||||
body_error(reason: any): any;
|
||||
request(reason: any): any;
|
||||
response(reason: any): any;
|
||||
send(reason: any): any;
|
||||
}
|
||||
|
||||
export interface IServerProcess {
|
||||
bridge: IServerBridge;
|
||||
config: IVerdaccioConfig;
|
||||
childFork: any;
|
||||
silence: boolean;
|
||||
init(): Promise<any>;
|
||||
stop(): void;
|
||||
bridge: IServerBridge;
|
||||
config: IVerdaccioConfig;
|
||||
childFork: any;
|
||||
silence: boolean;
|
||||
init(): Promise<any>;
|
||||
stop(): void;
|
||||
}
|
||||
|
||||
declare class verdaccio$PromiseAssert<IRequestPromise> extends Promise<any> {
|
||||
constructor(options: any): IRequestPromise;
|
||||
constructor(options: any): IRequestPromise;
|
||||
}
|
||||
|
||||
export interface IServerBridge {
|
||||
url: string;
|
||||
url: string;
|
||||
userAgent: string;
|
||||
authstr: string;
|
||||
request(options: any): typeof verdaccio$PromiseAssert;
|
||||
auth(name: string, password: string): IRequestPromise;
|
||||
logout(token: string): Promise<any>;
|
||||
auth(name: string, password: string): IRequestPromise;
|
||||
getPackage(name: string): Promise<any>;
|
||||
putPackage(name: string, data: any): Promise<any>;
|
||||
putVersion(name: string, version: string, data: any): Promise<any>;
|
||||
getTarball(name: string, filename: string): Promise<any>;
|
||||
putTarball(name: string, filename: string, data: any): Promise<any>;
|
||||
removeTarball(name: string): Promise<any>;
|
||||
removeSingleTarball(name: string, filename: string): Promise<any>;
|
||||
addTag(name: string, tag: string, version: string): Promise<any>;
|
||||
putTarballIncomplete(name: string, filename: string, data: any, size: number, cb: Function): Promise<any>;
|
||||
addPackage(name: string): Promise<any>;
|
||||
whoami(): Promise<any>;
|
||||
ping(): Promise<any>;
|
||||
debug(): IRequestPromise;
|
||||
request(options: any): typeof verdaccio$PromiseAssert;
|
||||
auth(name: string, password: string): IRequestPromise;
|
||||
logout(token: string): Promise<any>;
|
||||
auth(name: string, password: string): IRequestPromise;
|
||||
getPackage(name: string): Promise<any>;
|
||||
putPackage(name: string, data: any): Promise<any>;
|
||||
putVersion(name: string, version: string, data: any): Promise<any>;
|
||||
getTarball(name: string, filename: string): Promise<any>;
|
||||
putTarball(name: string, filename: string, data: any): Promise<any>;
|
||||
removeTarball(name: string): Promise<any>;
|
||||
removeSingleTarball(name: string, filename: string): Promise<any>;
|
||||
addTag(name: string, tag: string, version: string): Promise<any>;
|
||||
putTarballIncomplete(name: string, filename: string, data: any, size: number, cb: Function): Promise<any>;
|
||||
addPackage(name: string): Promise<any>;
|
||||
whoami(): Promise<any>;
|
||||
ping(): Promise<any>;
|
||||
debug(): IRequestPromise;
|
||||
}
|
|
@ -3,13 +3,13 @@ import type {IVerdaccioConfig} from './types';
|
|||
|
||||
export class VerdaccioConfig implements IVerdaccioConfig {
|
||||
|
||||
storagePath: string;
|
||||
configPath: string;
|
||||
domainPath: string;
|
||||
storagePath: string;
|
||||
configPath: string;
|
||||
domainPath: string;
|
||||
|
||||
constructor(storagePath: string, configPath: string, domainPath: string) {
|
||||
this.storagePath = storagePath;
|
||||
this.configPath = configPath;
|
||||
this.domainPath = domainPath;
|
||||
}
|
||||
constructor(storagePath: string, configPath: string, domainPath: string) {
|
||||
this.storagePath = storagePath;
|
||||
this.configPath = configPath;
|
||||
this.domainPath = domainPath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,66 +6,65 @@ import type {IRequestPromise} from '../../functional/lib/types';
|
|||
|
||||
describe('Request Functional', () => {
|
||||
|
||||
const restTest: string = "http://registry.npmjs.org/aaa";
|
||||
const restTest: string = "http://registry.npmjs.org/aaa";
|
||||
|
||||
describe('Request Functional', () => {
|
||||
test('PromiseAssert', () => {
|
||||
expect(_.isFunction(smartRequest)).toBeTruthy();
|
||||
});
|
||||
describe('Request Functional', () => {
|
||||
test('PromiseAssert', () => {
|
||||
expect(_.isFunction(smartRequest)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('basic resolve', (done) => {
|
||||
const requestPromise: IRequestPromise = new PromiseAssert((resolve, reject) => {
|
||||
resolve(1);
|
||||
});
|
||||
// $FlowFixMe
|
||||
requestPromise.then((result) => {
|
||||
expect(result).toBe(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('smartRequest Rest', () => {
|
||||
test('basic resolve', (done) => {
|
||||
const requestPromise: IRequestPromise = new PromiseAssert((resolve, reject) => {
|
||||
resolve(1);
|
||||
});
|
||||
// $FlowFixMe
|
||||
requestPromise.then((result) => {
|
||||
expect(result).toBe(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('smartRequest Rest', () => {
|
||||
|
||||
test('basic rest', (done) => {
|
||||
const options: any = {
|
||||
url: restTest,
|
||||
method: 'GET'
|
||||
};
|
||||
test('basic rest', (done) => {
|
||||
const options: any = {
|
||||
url: restTest,
|
||||
method: 'GET'
|
||||
};
|
||||
|
||||
smartRequest(options).then((result)=> {
|
||||
expect(_.isString(result)).toBeTruthy();
|
||||
done();
|
||||
})
|
||||
});
|
||||
smartRequest(options).then((result)=> {
|
||||
expect(_.isString(result)).toBeTruthy();
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
describe('smartRequest Status', () => {
|
||||
describe('smartRequest Status', () => {
|
||||
|
||||
test('basic check status 200', (done) => {
|
||||
const options: any = {
|
||||
url: restTest,
|
||||
method: 'GET'
|
||||
};
|
||||
// $FlowFixMe
|
||||
smartRequest(options).status(200).then((result)=> {
|
||||
expect(JSON.parse(result).name).toBe('aaa');
|
||||
done();
|
||||
})
|
||||
});
|
||||
test('basic check status 200', (done) => {
|
||||
const options: any = {
|
||||
url: restTest,
|
||||
method: 'GET'
|
||||
};
|
||||
// $FlowFixMe
|
||||
smartRequest(options).status(200).then((result)=> {
|
||||
expect(JSON.parse(result).name).toBe('aaa');
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
test('basic check status 404', (done) => {
|
||||
const options: any = {
|
||||
url: 'http://www.google.fake',
|
||||
method: 'GET'
|
||||
};
|
||||
// $FlowFixMe
|
||||
smartRequest(options).status(404).then((result)=> {
|
||||
// this never is resolved
|
||||
}, function(error) {
|
||||
expect(error.code).toBe('ENOTFOUND');
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
test('basic check status 404', (done) => {
|
||||
const options: any = {
|
||||
url: 'http://www.google.fake',
|
||||
method: 'GET'
|
||||
};
|
||||
// $FlowFixMe
|
||||
smartRequest(options).status(404).then((result)=> {
|
||||
// this never is resolved
|
||||
}, function(error) {
|
||||
expect(error.code).toBe('ENOTFOUND');
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue