File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ module.exports = CoreObject.extend({
20
20
this . _client = require ( 'then-redis' ) . createClient ( redisOptions ) ;
21
21
}
22
22
this . _maxNumberOfRecentUploads = 10 ;
23
+ this . _allowOverwrite = options . allowOverwrite ;
23
24
} ,
24
25
25
26
upload : function ( /*key, tag, value*/ ) {
@@ -43,13 +44,14 @@ module.exports = CoreObject.extend({
43
44
44
45
_uploadIfKeyDoesNotExist : function ( redisKey , value ) {
45
46
var client = this . _client ;
47
+ var allowOverwrite = ! ! this . _allowOverwrite ;
46
48
47
49
return Promise . resolve ( )
48
50
. then ( function ( ) {
49
51
return client . get ( redisKey ) ;
50
52
} )
51
53
. then ( function ( value ) {
52
- if ( value ) {
54
+ if ( value && ! allowOverwrite ) {
53
55
return Promise . reject ( 'Value already exists for key: ' + redisKey ) ;
54
56
}
55
57
} )
Original file line number Diff line number Diff line change @@ -50,6 +50,30 @@ describe('redis', function() {
50
50
} ) ;
51
51
} ) ;
52
52
53
+ it ( 'uploads the contents if the key already exists but allowOverwrite is true' , function ( ) {
54
+ var fileUploaded = false ;
55
+
56
+ var redis = new Redis ( {
57
+ allowOverwrite : true ,
58
+ redisClient : {
59
+ get : function ( key ) {
60
+ return Promise . resolve ( 'some-other-value' ) ;
61
+ } ,
62
+ set : function ( key , value ) {
63
+ fileUploaded = true ;
64
+ } ,
65
+ lpush : function ( ) { } ,
66
+ ltrim : function ( ) { }
67
+ }
68
+ } ) ;
69
+
70
+ var promise = redis . upload ( 'key' , 'value' ) ;
71
+ return assert . isFulfilled ( promise )
72
+ . then ( function ( ) {
73
+ assert . ok ( fileUploaded ) ;
74
+ } ) ;
75
+ } ) ;
76
+
53
77
it ( 'updates the list of recent uploads once upload is successful' , function ( ) {
54
78
var recentUploads = [ ] ;
55
79
You can’t perform that action at this time.
0 commit comments