1
+ 'use strict' ;
2
+
3
+ var expect = require ( 'chai' ) . expect ;
4
+ var injectr = require ( 'injectr' ) ;
5
+ var sinon = require ( 'sinon' ) ;
6
+
7
+ describe ( 'registry : domain : url-parser' , function ( ) {
8
+
9
+ var parsed ;
10
+ var execute = function ( url , returnVersion , callback ) {
11
+ var urlParser = injectr ( '../../registry/domain/url-parser.js' , {
12
+ '../../utils/request' : sinon . stub ( ) . yields ( null , JSON . stringify ( {
13
+ requestVersion : returnVersion
14
+ } ) )
15
+ } ) ;
16
+
17
+ urlParser . parse ( url , function ( err , res ) {
18
+ parsed = res ;
19
+ callback ( ) ;
20
+ } ) ;
21
+ } ;
22
+
23
+ describe ( 'when parsing http://www.registry.com/api/v2/component-name' , function ( ) {
24
+
25
+ before ( function ( done ) {
26
+ execute ( 'http://www.registry.com/api/v2/component-name' , '' , done ) ;
27
+ } ) ;
28
+
29
+ it ( 'componentName should be component-name' , function ( ) {
30
+ expect ( parsed . componentName ) . to . equal ( 'component-name' ) ;
31
+ } ) ;
32
+
33
+ it ( 'version should be blank' , function ( ) {
34
+ expect ( parsed . version ) . to . equal ( '' ) ;
35
+ } ) ;
36
+
37
+ it ( 'registryUrl should be http://www.registry.com/api/v2/' , function ( ) {
38
+ expect ( parsed . registryUrl ) . to . equal ( 'http://www.registry.com/api/v2/' ) ;
39
+ } ) ;
40
+
41
+ it ( 'parameters should be {}' , function ( ) {
42
+ expect ( parsed . parameters ) . to . eql ( { } ) ;
43
+ } ) ;
44
+
45
+ it ( 'clientHref should be http://www.registry.com/api/v2/oc-client/client.js' , function ( ) {
46
+ expect ( parsed . clientHref ) . to . equal ( 'http://www.registry.com/api/v2/oc-client/client.js' ) ;
47
+ } ) ;
48
+ } ) ;
49
+
50
+ describe ( 'when parsing http://www.registry.com/component-name/~1.0.0/?hello=world' , function ( ) {
51
+
52
+ before ( function ( done ) {
53
+ execute ( 'http://www.registry.com/component-name/~1.0.0/?hello=world' , '~1.0.0' , done ) ;
54
+ } ) ;
55
+
56
+ it ( 'componentName should be component-name' , function ( ) {
57
+ expect ( parsed . componentName ) . to . equal ( 'component-name' ) ;
58
+ } ) ;
59
+
60
+ it ( 'version should be blank' , function ( ) {
61
+ expect ( parsed . version ) . to . equal ( '~1.0.0' ) ;
62
+ } ) ;
63
+
64
+ it ( 'registryUrl should be http://www.registry.com/' , function ( ) {
65
+ expect ( parsed . registryUrl ) . to . equal ( 'http://www.registry.com/' ) ;
66
+ } ) ;
67
+
68
+ it ( 'parameters should be { hello: \'world\'}' , function ( ) {
69
+ expect ( parsed . parameters ) . to . eql ( { hello : 'world' } ) ;
70
+ } ) ;
71
+
72
+ it ( 'clientHref should be http://www.registry.com/oc-client/client.js' , function ( ) {
73
+ expect ( parsed . clientHref ) . to . equal ( 'http://www.registry.com/oc-client/client.js' ) ;
74
+ } ) ;
75
+ } ) ;
76
+
77
+ describe ( 'when parsing http://www.registry.com/12345/~1.0.0?hello=world' , function ( ) {
78
+
79
+ before ( function ( done ) {
80
+ execute ( 'http://www.registry.com/12345/~1.0.0?hello=world' , '~1.0.0' , done ) ;
81
+ } ) ;
82
+
83
+ it ( 'componentName should be 12345' , function ( ) {
84
+ expect ( parsed . componentName ) . to . equal ( '12345' ) ;
85
+ } ) ;
86
+
87
+ it ( 'version should be blank' , function ( ) {
88
+ expect ( parsed . version ) . to . equal ( '~1.0.0' ) ;
89
+ } ) ;
90
+
91
+ it ( 'registryUrl should be http://www.registry.com/' , function ( ) {
92
+ expect ( parsed . registryUrl ) . to . equal ( 'http://www.registry.com/' ) ;
93
+ } ) ;
94
+
95
+ it ( 'parameters should be { hello: \'world\'}' , function ( ) {
96
+ expect ( parsed . parameters ) . to . eql ( { hello : 'world' } ) ;
97
+ } ) ;
98
+
99
+ it ( 'clientHref should be http://www.registry.com/oc-client/client.js' , function ( ) {
100
+ expect ( parsed . clientHref ) . to . equal ( 'http://www.registry.com/oc-client/client.js' ) ;
101
+ } ) ;
102
+ } ) ;
103
+ } ) ;
0 commit comments