@@ -16,6 +16,7 @@ import {
1616 filterFilesForUpdate ,
1717 findAttachments ,
1818 findPagesToDelete ,
19+ getAttachmentsDirectory ,
1920 getMessageFromAPIError ,
2021 getNextVersion ,
2122 getTitle ,
@@ -2907,6 +2908,75 @@ const runFindAttachments = () => {
29072908 } ) ;
29082909} ;
29092910
2911+ const runGetAttachmentsDirectory = ( ) => {
2912+ const suiteLabel = ( label : string ) => `GetAttachmentsDirectory_${ label } ` ;
2913+
2914+ const check = (
2915+ expected : string ,
2916+ baseDirectory : string ,
2917+ attachmentsToUpload : string [ ] ,
2918+ fileName : string
2919+ ) => {
2920+ assertEquals (
2921+ getAttachmentsDirectory ( baseDirectory , fileName , attachmentsToUpload ) ,
2922+ expected
2923+ ) ;
2924+ } ;
2925+
2926+ unitTest ( suiteLabel ( "empty_to_upload" ) , async ( ) => {
2927+ const expected = "" ;
2928+ const baseDirectory = "/Users/fake-base" ;
2929+ check ( expected , baseDirectory , [ ] , "file-name.png" ) ;
2930+ } ) ;
2931+
2932+ unitTest ( suiteLabel ( "empty_fileName" ) , async ( ) => {
2933+ const expected = "" ;
2934+ const attachmentsToUpload = [ "file1.png" , "file2.png" ] ;
2935+ const baseDirectory = "/Users/fake-base" ;
2936+ check ( expected , baseDirectory , attachmentsToUpload , "" ) ;
2937+ } ) ;
2938+
2939+ unitTest ( suiteLabel ( "simple" ) , async ( ) => {
2940+ const expected = "/Users/fake-base" ;
2941+
2942+ const baseDirectory = "/Users/fake-base" ;
2943+ const attachmentsToUpload = [ "file1.png" ] ;
2944+ const fileName = "fake-file.xml" ;
2945+
2946+ check ( expected , baseDirectory , attachmentsToUpload , fileName ) ;
2947+ } ) ;
2948+
2949+ unitTest ( suiteLabel ( "site_in_root" ) , async ( ) => {
2950+ const expected = "/Users/fake-base" ;
2951+
2952+ const baseDirectory = "/Users/fake-base/_site" ;
2953+ const attachmentsToUpload = [ "file1.png" ] ;
2954+ const fileName = "fake-file.xml" ;
2955+
2956+ check ( expected , baseDirectory , attachmentsToUpload , fileName ) ;
2957+ } ) ;
2958+
2959+ unitTest ( suiteLabel ( "site_nested" ) , async ( ) => {
2960+ const expected = "/Users/fake-base/fake-parent" ;
2961+
2962+ const baseDirectory = "/Users/fake-base/_site" ;
2963+ const attachmentsToUpload = [ "file1.png" ] ;
2964+ const fileName = "fake-parent/fake-file.xml" ;
2965+
2966+ check ( expected , baseDirectory , attachmentsToUpload , fileName ) ;
2967+ } ) ;
2968+
2969+ unitTest ( suiteLabel ( "site_nested_multi" ) , async ( ) => {
2970+ const expected = "/Users/fake-base/fake-grand-parent/fake-parent" ;
2971+
2972+ const baseDirectory = "/Users/fake-base/_site" ;
2973+ const attachmentsToUpload = [ "file1.png" ] ;
2974+ const fileName = "fake-grand-parent/fake-parent/fake-file.xml" ;
2975+
2976+ check ( expected , baseDirectory , attachmentsToUpload , fileName ) ;
2977+ } ) ;
2978+ } ;
2979+
29102980const runUpdateImagePathsForContentBody = ( ) => {
29112981 const suiteLabel = ( label : string ) =>
29122982 `UpdateImagePathsForContentBody_${ label } ` ;
@@ -2974,9 +3044,8 @@ if (runAllTests) {
29743044 runExtractLinks ( ) ;
29753045 runUpdateLinks ( ) ;
29763046 runFindAttachments ( ) ;
3047+ runGetAttachmentsDirectory ( ) ;
29773048 runUpdateImagePathsForContentBody ( ) ;
29783049} else {
2979- // runSpaceCreatesWithNesting();
2980- // runSpaceUpdatesWithNesting();
2981- runSpaceUpdatesWithNestedMoves ( ) ;
3050+ runGetAttachmentsDirectory ( ) ;
29823051}
0 commit comments