Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit b5ee142

Browse files
authored
Fix/url parsing (#8)
* build(Source control cleanup): Added "files" explicitly to package.json * build(dist folder): Removed Dist folder from source control * build(gitignore): Added dist and dist_tests to gitignore * build(package.json): Updated Typescript version to 2.3.0 * refactor(SnConfig): Removed Behavior, FieldDecorator, FieldModel, FieldModelStore (these will be par * build(tslint): variable-name checking syntax fix * build(package.json): Updated sn-client-js dependency to development-1, modified version, published t * build(tslint): fixed tslint scope from NPM script * fix(SnConfig): Fixed CommandLineArgs valid commands list * build(package.json): TS version update, added sn.config.js to included files * fix(SnConfigReader): removed JwtTokenTemplate from CLI options * fix(DownloadHandler): fixed url parsing * build(tsconfig): removed explicit type declaration restrictions from tsconfigs * fix(Download): Fixed URL parsing, now works with and without protocol declaration * build(mocha-typescrip version set explicitly to 1.0.23 (known issue: https://github.com/pana-cc/moch * chore(package.json): Updated dependencies, Test method syntax (mocha-typescript change)
1 parent 39f77e1 commit b5ee142

12 files changed

Lines changed: 110 additions & 85 deletions

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"outFiles": [
1616
"${workspaceRoot}\\dist\\**\\*.js"
1717
],
18+
"cwd": "${workspaceRoot}\\..\\aurelia-mook\\",
1819
"console": "integratedTerminal",
1920
"preLaunchTask": "build"
2021
},

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,33 @@
4747
},
4848
"homepage": "https://github.com/SenseNet/sn-client-cli#readme",
4949
"devDependencies": {
50-
"@types/chai": "^3.4.35",
51-
"@types/mocha": "^2.2.40",
52-
"@types/node": "^7.0.12",
50+
"@types/chai": "^3.5.2",
5351
"chai": "^3.5.0",
5452
"commitizen": "^2.9.6",
55-
"mocha": "^3.2.0",
56-
"mocha-typescript": "^1.0.23",
53+
"mocha": "^3.4.1",
54+
"mocha-typescript": "^1.1.2",
5755
"prompt": "^1.0.0",
58-
"tslint": "^5.0.0",
59-
"typedoc": "^0.5.9",
56+
"tslint": "^5.2.0",
57+
"typedoc": "^0.7.0",
6058
"typescript": "^2.3.2"
6159
},
6260
"dependencies": {
61+
"@types/chai": "^3.5.2",
62+
"@types/mocha": "^2.2.41",
63+
"@types/node": "^7.0.18",
6364
"adm-zip": "^0.4.7",
64-
"command-line-args": "^4.0.2",
65+
"command-line-args": "^4.0.4",
6566
"command-line-commands": "^2.0.0",
6667
"command-line-usage": "^4.0.0",
67-
"codecov": "^1.0.1",
68+
"codecov": "^2.2.0",
6869
"del": "^2.2.2",
6970
"gulp": "^3.9.1",
70-
"gulp-mocha": "^4.3.0",
71+
"gulp-mocha": "^4.3.1",
7172
"gulp-promisify": "^1.2.2",
7273
"gulp-run": "^1.7.1",
7374
"gulp-typedoc": "^2.0.2",
7475
"path": "^0.12.7",
75-
"sn-client-js": "1.1.1-development.3"
76+
"sn-client-js": "2.0.0-RC.1"
7677
},
7778
"czConfig": {
7879
"path": "node_modules/cz-conventional-changelog"

src/utils/download.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Http from 'http';
2+
import * as URL from 'url';
23

34
/**
45
* This class represents a Download from a specified Sense/Net Repository
@@ -53,12 +54,11 @@ export class Download {
5354
*/
5455
public async GetAsBufferAsync(): Promise<Buffer> {
5556
return new Promise<Buffer>((resolve) => {
56-
57-
const url = new URL(this.host);
58-
57+
const url = URL.parse(this.host);
5958
Http.get({
59+
protocol: url.protocol,
6060
headers: this.headers,
61-
host: url.origin,
61+
host: url.host || url.path,
6262
path: this.path,
6363
}, (response: Http.IncomingMessage) => this.HandleResponse(response, resolve));
6464
});

test/AskTests.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ const expect = Chai.expect;
88
@suite('Ask Tests')
99
export class AskTests {
1010

11-
@test('should return an awaitable Promise')
12-
public TextAsync() {
11+
@test
12+
public 'Ask Text should return an awaitable Promise'() {
1313
const promise = Ask.TextAsync('Text');
1414
expect(promise).to.be.instanceOf(Promise, 'Should return a promise');
1515
}
1616

17-
@test('Ask text, resolve with override')
18-
public TextOverride(done) {
17+
@test
18+
public 'Ask text, resolve with override'(done) {
1919
Prompt.override = {
2020
Text: 'alma'
2121
};
@@ -25,8 +25,8 @@ export class AskTests {
2525
});
2626
}
2727

28-
@test('Ask password, resolve with override')
29-
public PasswordOverride(done) {
28+
@test
29+
public 'Ask password, resolve with override'(done) {
3030
Prompt.override = {
3131
Text: 'alma'
3232
};
@@ -36,20 +36,20 @@ export class AskTests {
3636
});
3737
}
3838

39-
@test('should return an awaitable Promise')
40-
public PasswordAsync() {
39+
@test
40+
public 'Ask Password should return an awaitable Promise'() {
4141
const promise = Ask.PasswordAsync('Password');
4242
expect(promise).to.be.an.instanceOf(Promise);
4343
}
4444

45-
@test('should create Prompt question from config field name')
46-
public createQuestionFromConfig() {
45+
@test
46+
public 'should create Prompt question from config field name'() {
4747
const q = Ask.createPromptQuestionFromConfigName('SnConfigModel.RepositoryUrl');
4848
expect(q.name).to.be.eq('RepositoryUrl');
4949
}
5050

51-
@test('should return an awaitable Promise')
52-
public MissingConfigs() {
51+
@test
52+
public 'should return an awaitable Promise'() {
5353
const promise = Ask.MissingConfigs();
5454
expect(promise).to.be.an.instanceOf(Promise);
5555
}

test/DownloadTests.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ export class DownloadTests {
1414

1515
}
1616

17-
@test('Shouldn\'t have custom headers by default')
18-
public EmptyHeaders() {
17+
@test
18+
public 'Shouldn\'t have custom headers by default'() {
1919
expect(Object.keys(this.download['headers']).length).to.be.eq(0);
2020

2121
}
2222

23-
@test('Should have a proper base64 encoded Basic Authorization header after setting up Authenticate')
24-
public BasicAuthHeaders() {
23+
@test
24+
public 'Should have a proper base64 encoded Basic Authorization header after setting up Authenticate'() {
2525
this.download.Authenticate('username', 'password');
2626
expect(this.download['headers']['Authorization']).to.be.eq('Basic dXNlcm5hbWU6cGFzc3dvcmQ=');
2727
}
2828

29-
@test('Should return the file as awaitable Promise on GetAsBufferAsync')
30-
public GetAsBufferAsync() {
29+
@test
30+
public 'Should return the file as awaitable Promise on GetAsBufferAsync'() {
3131
const buffer = this.download.GetAsBufferAsync();
3232
expect(buffer).to.be.an.instanceOf(Promise);
3333
}
3434

35-
@test('HandleResponse')
36-
public testHandleResponse(done) {
35+
@test
36+
public 'HandleResponse'(done) {
3737
const httpMsg: Http.IncomingMessage = new Events.EventEmitter() as Http.IncomingMessage;
3838
httpMsg.headers = {
3939
'content-length': 3

test/PathHelperTests.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ export class PathHelperTests {
1313
this.PathHelper = new PathHelper('c:/temp/package/../package', 'c:/temp/package/../package/node_modules/sn-client-js', 'c:/temp/package/../package/node_modules/sn-client-cli');
1414
}
1515

16-
@test('Should normalize PackageRoot path')
17-
public PackageRootPath() {
16+
@test
17+
public 'Should normalize PackageRoot path'() {
1818
expect(this.PathHelper.PackageRootPath).to.be.eq(`c:${Path.sep}temp${Path.sep}package`);
1919
}
2020

21-
@test('Should normalize SnClient path')
22-
public SnClientPath() {
21+
@test
22+
public 'Should normalize SnClient path'() {
2323
expect(this.PathHelper.SnClientPath).to.be.eq(`c:${Path.sep}temp${Path.sep}package${Path.sep}node_modules${Path.sep}sn-client-js`);
2424

2525
}
2626

27-
@test('Should provide realible relative path to PackageRootPath')
28-
public RealiblePackageRoot() {
27+
@test
28+
public 'Should provide realible relative path to PackageRootPath'() {
2929
expect(this.PathHelper.GetRelativeToPackageRootPath('./alma')).to.be.eq(Path.join(this.PathHelper.PackageRootPath, './alma'));
3030
}
3131

32-
@test('Should provide realible relative path to SnClientPath')
33-
public RealibleSnClientPath() {
32+
@test
33+
public 'Should provide realible relative path to SnClientPath'() {
3434
expect(this.PathHelper.GetRelativeToSnClientPath('./alma')).to.be.eq(Path.join(this.PathHelper.SnClientPath, './alma'));
3535

3636
}

test/SnConfigReaderTests.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ export class SnConfigReaderTests {
1313
this.reader = new SnConfigReader(SnCliConfigModel, process.cwd());
1414
}
1515

16-
@test('ReadConfigFile should return an awaitable promise')
17-
public Read() {
16+
@test
17+
public 'ReadConfigFile should return an awaitable promise'() {
1818
const promise = this.reader.ReadConfigFile();
1919
expect(promise).to.be.an.instanceOf(Promise);
2020
}
2121

22-
@test('Should create a new config if not exists')
23-
public async ReadNonExisting() {
22+
@test
23+
public async 'Should create a new config if not exists'() {
2424
await this.reader.ReadConfigFile('invalidConfig.js');
2525
expect(this.reader.Config).to.be.instanceof(SnCliConfigModel);
2626
}
2727

28-
@test('ValidateAsync should return an awaitable promise')
29-
public ValidatePromise() {
28+
@test
29+
public 'ValidateAsync should return an awaitable promise'() {
3030
const promise = this.reader.ValidateAsync('RepositoryUrl', 'UserName', 'Password');
3131
expect(promise).to.be.an.instanceOf(Promise);
3232
}
3333

34-
@test('Shouldn resolve when all fields are provided')
35-
public async ValidateResolve() {
34+
@test
35+
public async 'Shouldn resolve when all fields are provided'() {
3636
this.reader.Config = {
3737
RepositoryUrl: 'url',
3838
UserName: 'username',
@@ -42,8 +42,8 @@ export class SnConfigReaderTests {
4242
expect(cfg.RepositoryUrl).to.be.eq('url');
4343
}
4444

45-
@test('Should throw an error if a field is provided but disallowed form config by behavior')
46-
public ValidateShouldThrowWhenNotAllowed(done) {
45+
@test
46+
public 'Should throw an error if a field is provided but disallowed form config by behavior'(done) {
4747
this.reader.Config = {
4848
RepositoryUrl: '',
4949
UserName: 'user',
@@ -56,8 +56,8 @@ export class SnConfigReaderTests {
5656
.catch(() => done());
5757
}
5858

59-
@test('OverrideConfig should override provided value')
60-
public OverrideConfigTest() {
59+
@test
60+
public 'OverrideConfig should override provided value'() {
6161

6262
this.reader.Config = {
6363
RepositoryUrl: 'url',

test/SnConfigTests.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as Chai from 'chai';
2+
import { suite, test } from 'mocha-typescript';
3+
4+
const expect = Chai.expect;
5+
6+
@suite('SnConfig Tests')
7+
export class SnConfigTests {
8+
9+
@test
10+
public 'SnConfigFieldModel Should be constructed with SnConfigBehavior.Default'() {
11+
const fieldModel = new SnConfigFieldModel();
12+
expect(fieldModel.Behavior).to.be.eq(SnConfigBehavior.Default);
13+
}
14+
15+
@test
16+
public 'SnConfigFieldModelStore Should throw error if entity isn\'t in the store '() {
17+
const find = () => { SnConfigFieldModelStore.Get('exampleFieldName'); };
18+
expect(find).to.throw(Error);
19+
}
20+
21+
@test
22+
public 'SnConfigFieldModelStore Should throw an error if you try to add a field that already exists'() {
23+
const add = () => { SnConfigFieldModelStore.Add({ FieldName: 'Example', Question: 'ExampleQuestion', Behavior: SnConfigBehavior.Default }); };
24+
add(); // add once
25+
expect(add).to.throw(Error);
26+
}
27+
28+
@test
29+
public 'GetCommandOptions should return only commands that has AllowFromCommandLine flag'() {
30+
const commands = SnConfigFieldModelStore.GetCommandOptions();
31+
commands.forEach((command) => {
32+
const isAllowed = (command.Behavior & SnConfigBehavior.AllowFromCommandLine) === SnConfigBehavior.AllowFromCommandLine;
33+
expect(isAllowed).to.eq(true);
34+
});
35+
36+
}
37+
38+
}

test/StageTests.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,36 @@ export class StageTests {
1717
this.stage = new Stage(this.pathHelper);
1818
}
1919

20-
@test('Should have a proper temp folder path')
21-
public TempFolderPath() {
20+
@test
21+
public 'Should have a proper temp folder path'() {
2222
expect(this.stage.TempFolderPath).to.be.eq(Path.join(this.pathHelper.SnClientPath, 'tmp'));
2323
}
2424

25-
@test('Prepare Should return an awaitable promise')
26-
public PreparePromise() {
25+
@test
26+
public 'Prepare Should return an awaitable promise'() {
2727
const promise = this.stage.PrepareAsync();
2828
expect(promise).to.be.an.instanceOf(Promise);
2929
}
3030

31-
@test('InitializeConfigAsync Should return an awaitable promise')
32-
public IniConfigPromise() {
31+
@test
32+
public 'InitializeConfigAsync Should return an awaitable promise'() {
3333
const promise = this.stage.InitializeConfigAsync();
3434
expect(promise).to.be.an.instanceOf(Promise);
3535
}
3636

37-
@test('UpdateModule Should return an awaitable promise')
38-
public UpdatePromise() {
37+
@test
38+
public 'UpdateModule Should return an awaitable promise'() {
3939
const promise = this.stage.UpdateModuleAsync();
4040
expect(promise).to.be.an.instanceOf(Promise);
4141
}
4242

43-
@test('CallGulpAsync')
44-
public async CallGulpAsync() {
43+
@test
44+
public async 'CallGulpAsync'() {
4545
await this.stage.CallGulpRunAsync('', __dirname);
4646
}
4747

48-
@test('CallGulpAsyncError')
49-
public CallGulpAsyncError(done) {
48+
@test
49+
public 'CallGulpAsyncError'(done) {
5050
this.stage.CallGulpRunAsync('badCommand', __dirname).then(
5151
() => { done('Error expeced'); },
5252
(err) => { done(); }

test/tsconfig.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
"experimentalDecorators": true,
77
"target": "es2015",
88
"sourceMap": true,
9-
"inlineSources": true,
10-
"types": [
11-
"node",
12-
"mocha",
13-
"chai"
14-
]
9+
"inlineSources": true
1510
}
1611
}

0 commit comments

Comments
 (0)