File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ export default class Model {
132
132
133
133
static url ( id ?: string | number ) : string {
134
134
let endpoint = this . endpoint || `/${ this . jsonapiType } ` ;
135
- let base = `${ this . baseUrl } ${ this . apiNamespace } ${ endpoint } ` ;
135
+ let base = `${ this . fullBasePath ( ) } ${ endpoint } ` ;
136
136
137
137
if ( id ) {
138
138
base = `${ base } /${ id } ` ;
@@ -141,6 +141,10 @@ export default class Model {
141
141
return base ;
142
142
}
143
143
144
+ static fullBasePath ( ) : string {
145
+ return `${ this . baseUrl } ${ this . apiNamespace } ` ;
146
+ }
147
+
144
148
static fromJsonapi ( resource : japiResource , payload : japiDoc ) : any {
145
149
return deserialize ( resource , payload ) ;
146
150
}
Original file line number Diff line number Diff line change @@ -76,6 +76,33 @@ describe('Model', function() {
76
76
} ) ;
77
77
} ) ;
78
78
79
+ describe ( '.url' , function ( ) {
80
+ context ( 'Default base URL generation method' , function ( ) {
81
+ it ( 'should append the baseUrl, apiNamespace, and jsonapi type' , function ( ) {
82
+ class DefaultBaseUrl extends ApplicationRecord {
83
+ static baseUrl : string = 'http://base.com'
84
+ static apiNamespace : string = '/namespace/v1'
85
+ static jsonapiType : string = 'testtype'
86
+ }
87
+
88
+ expect ( DefaultBaseUrl . url ( 'testId' ) ) . to . eq ( 'http://base.com/namespace/v1/testtype/testId' )
89
+ } )
90
+ } )
91
+
92
+ context ( 'Base URL path generation is overridden' , function ( ) {
93
+ it ( 'should use the result of the override function' , function ( ) {
94
+ class OverriddenBaseUrl extends ApplicationRecord {
95
+ static jsonapiType : string = 'testtype'
96
+ static fullBasePath ( ) : string {
97
+ return 'http://overridden.base'
98
+ }
99
+ }
100
+
101
+ expect ( OverriddenBaseUrl . url ( 'testId' ) ) . to . eq ( 'http://overridden.base/testtype/testId' )
102
+ } )
103
+ } )
104
+ } )
105
+
79
106
describe ( '#getJWT' , function ( ) {
80
107
beforeEach ( function ( ) {
81
108
ApplicationRecord . jwt = 'g3tm3' ;
You can’t perform that action at this time.
0 commit comments