File tree Expand file tree Collapse file tree 5 files changed +63
-4
lines changed Expand file tree Collapse file tree 5 files changed +63
-4
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ async function createSharesTable(queryRunner: QueryRunner): Promise<void> {
3030 type : 'character varying' ,
3131 isNullable : false ,
3232 } ,
33+ {
34+ name : 'enabled' ,
35+ type : 'boolean' ,
36+ isNullable : false ,
37+ } ,
3338 {
3439 name : 'require_login' ,
3540 type : 'boolean' ,
Original file line number Diff line number Diff line change @@ -10,10 +10,20 @@ export class ShareInfoDto {
1010 shareType : ShareType ;
1111 expiresAt : Date | null ;
1212
13- static fromEntity ( share : Share | null ) : ShareInfoDto {
14- if ( ! share ) {
15- return new ShareInfoDto ( ) ;
16- }
13+ static new ( namespaceId : string , resourceId : string ) : ShareInfoDto {
14+ const dto = new ShareInfoDto ( ) ;
15+ dto . id = '' ;
16+ dto . namespaceId = namespaceId ;
17+ dto . resourceId = resourceId ;
18+ dto . enabled = false ;
19+ dto . requireLogin = false ;
20+ dto . passwordEnabled = false ;
21+ dto . shareType = ShareType . ALL ;
22+ dto . expiresAt = null ;
23+ return dto ;
24+ }
25+
26+ static fromEntity ( share : Share ) : ShareInfoDto {
1727 const dto = new ShareInfoDto ( ) ;
1828 dto . id = share . id ;
1929 dto . namespaceId = share . namespaceId ;
Original file line number Diff line number Diff line change 1+ import { TestClient } from 'test/test-client' ;
2+
3+ describe ( 'SharesController (e2e)' , ( ) => {
4+ let client : TestClient ;
5+
6+ beforeAll ( async ( ) => {
7+ client = await TestClient . create ( ) ;
8+ } ) ;
9+
10+ afterAll ( async ( ) => {
11+ await client . close ( ) ;
12+ } ) ;
13+
14+ it ( 'update and get share info' , async ( ) => {
15+ const password = 'test-password' ;
16+ let res = await client
17+ . patch (
18+ `/api/v1/namespaces/${ client . namespace . id } /resources/${ client . namespace . root_resource_id } /share` ,
19+ )
20+ . send ( {
21+ enabled : true ,
22+ password,
23+ } ) ;
24+ expect ( res . status ) . toBe ( 200 ) ;
25+
26+ res = await client . get (
27+ `/api/v1/namespaces/${ client . namespace . id } /resources/${ client . namespace . root_resource_id } /share` ,
28+ ) ;
29+ expect ( res . status ) . toBe ( 200 ) ;
30+ expect ( res . body . namespace_id ) . toBe ( client . namespace . id ) ;
31+ expect ( res . body . resource_id ) . toBe ( client . namespace . root_resource_id ) ;
32+ expect ( res . body . enabled ) . toBe ( true ) ;
33+ expect ( res . body . password_enabled ) . toBe ( true ) ;
34+ } ) ;
35+ } ) ;
Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ export class SharesService {
2222 resourceId,
2323 } ,
2424 } ) ;
25+ if ( ! share ) {
26+ return ShareInfoDto . new ( namespaceId , resourceId ) ;
27+ }
2528 return ShareInfoDto . fromEntity ( share ) ;
2629 }
2730
Original file line number Diff line number Diff line change @@ -97,6 +97,12 @@ export class TestClient {
9797 . set ( 'Authorization' , `Bearer ${ this . user . token } ` ) ;
9898 }
9999
100+ patch ( url : string ) {
101+ return this . request ( )
102+ . patch ( url )
103+ . set ( 'Authorization' , `Bearer ${ this . user . token } ` ) ;
104+ }
105+
100106 public static async create ( ) : Promise < TestClient > {
101107 const moduleFixture : TestingModule = await Test . createTestingModule ( {
102108 imports : [ AppModule . forRoot ( [ ] ) ] ,
You can’t perform that action at this time.
0 commit comments