Code refactoring (#725)
This commit is contained in:
Родитель
9fde20be53
Коммит
55949427b5
|
@ -72,7 +72,7 @@ class AccountManager {
|
|||
}
|
||||
|
||||
public isAuthenticated(throwIfUnauthorized?: boolean): Promise<boolean> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
var request: superagent.Request = superagent.get(this._serverUrl + urlEncode`/authenticated`);
|
||||
if (this._proxy) (<any>request).proxy(this._proxy);
|
||||
this.attachCredentials(request);
|
||||
|
@ -367,7 +367,7 @@ class AccountManager {
|
|||
private packageFileFromPath(filePath: string): Promise<PackageFile> {
|
||||
var getPackageFilePromise: Promise<PackageFile>;
|
||||
if (fs.lstatSync(filePath).isDirectory()) {
|
||||
getPackageFilePromise = new Promise<PackageFile>((resolve: (file: PackageFile) => void, reject: (reason: Error) => void): void => {
|
||||
getPackageFilePromise = new Promise<PackageFile>((resolve: (file: PackageFile) => void, reject: (reason: Error) => void): void => {
|
||||
var directoryPath: string = filePath;
|
||||
|
||||
recursiveFs.readdirr(directoryPath, (error?: any, directories?: string[], files?: string[]): void => {
|
||||
|
@ -405,9 +405,9 @@ class AccountManager {
|
|||
});
|
||||
});
|
||||
} else {
|
||||
getPackageFilePromise = new Promise<PackageFile>((resolve: (file: PackageFile) => void, reject: (reason: Error) => void): void => {
|
||||
resolve({ isTemporary: false, path: filePath });
|
||||
});
|
||||
getPackageFilePromise = new Promise<PackageFile>((resolve: (file: PackageFile) => void, reject: (reason: Error) => void): void => {
|
||||
resolve({ isTemporary: false, path: filePath });
|
||||
});
|
||||
}
|
||||
return getPackageFilePromise;
|
||||
}
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
// ./superagent-mock-config.js file
|
||||
module.exports = [
|
||||
{
|
||||
pattern: 'http://localhost/(\\w+)/',
|
||||
{
|
||||
pattern: 'http://localhost/(\\w+)/',
|
||||
|
||||
/**
|
||||
* returns the data
|
||||
*
|
||||
* @param match array Result of the resolution of the regular expression
|
||||
* @param params object sent by 'send' function
|
||||
*/
|
||||
fixtures: function (match, params) {
|
||||
return {text: "Error", status: 403, ok: false};
|
||||
/**
|
||||
* returns the data
|
||||
*
|
||||
* @param match array Result of the resolution of the regular expression
|
||||
* @param params object sent by 'send' function
|
||||
*/
|
||||
fixtures: function (match, params) {
|
||||
return { text: "Error", status: 403, ok: false };
|
||||
|
||||
/**
|
||||
* example:
|
||||
* request.get('https://error.example/404').end(function(err, res){
|
||||
* console.log(err); // 404
|
||||
* })
|
||||
*/
|
||||
if (match[1] === '404') {
|
||||
throw new Error(404);
|
||||
}
|
||||
/**
|
||||
* example:
|
||||
* request.get('https://error.example/404').end(function(err, res){
|
||||
* console.log(err); // 404
|
||||
* })
|
||||
*/
|
||||
if (match[1] === '404') {
|
||||
throw new Error(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* example:
|
||||
* request.get('https://error.example/200').end(function(err, res){
|
||||
* console.log(res.body); // "Data fixtures"
|
||||
* })
|
||||
*/
|
||||
/**
|
||||
* example:
|
||||
* request.get('https://error.example/200').end(function(err, res){
|
||||
* console.log(res.body); // "Data fixtures"
|
||||
* })
|
||||
*/
|
||||
|
||||
/**
|
||||
* example:
|
||||
* request.get('https://domain.send.example/').send({superhero: "me"}).end(function(err, res){
|
||||
* console.log(res.body); // "Data fixtures - superhero:me"
|
||||
* })
|
||||
*/
|
||||
if(params["superhero"]) {
|
||||
return 'Data fixtures - superhero:' + params["superhero"];
|
||||
} else {
|
||||
return 'Data fixtures';
|
||||
}
|
||||
},
|
||||
/**
|
||||
* example:
|
||||
* request.get('https://domain.send.example/').send({superhero: "me"}).end(function(err, res){
|
||||
* console.log(res.body); // "Data fixtures - superhero:me"
|
||||
* })
|
||||
*/
|
||||
if (params["superhero"]) {
|
||||
return 'Data fixtures - superhero:' + params["superhero"];
|
||||
} else {
|
||||
return 'Data fixtures';
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* returns the result of the request
|
||||
*
|
||||
* @param match array Result of the resolution of the regular expression
|
||||
* @param data mixed Data returns by `fixtures` attribute
|
||||
*/
|
||||
callback: function (match, data) {
|
||||
return data;
|
||||
}
|
||||
},
|
||||
];
|
||||
/**
|
||||
* returns the result of the request
|
||||
*
|
||||
* @param match array Result of the resolution of the regular expression
|
||||
* @param data mixed Data returns by `fixtures` attribute
|
||||
*/
|
||||
callback: function (match, data) {
|
||||
return data;
|
||||
}
|
||||
},
|
||||
];
|
||||
|
|
Загрузка…
Ссылка в новой задаче