@@ -2756,7 +2756,7 @@ describe('Record', () => {
2756
2756
2757
2757
try {
2758
2758
// @ts -expect-error because this test intentionally specifies an immutable property that is not present in RecordUpdateOptions.
2759
- await record ! . update ( { dataFormat : 'application/json ' } ) ;
2759
+ await record ! . update ( { schema : 'bar/baz ' } ) ;
2760
2760
expect . fail ( 'Expected an exception to be thrown' ) ;
2761
2761
} catch ( error : any ) {
2762
2762
expect ( error . message ) . to . include ( 'is an immutable property. Its value cannot be changed.' ) ;
@@ -2876,6 +2876,36 @@ describe('Record', () => {
2876
2876
expect ( updateResultWithNullTags . status . code ) . to . equal ( 202 ) ;
2877
2877
expect ( record . tags ) . to . not . exist ; // removed
2878
2878
} ) ;
2879
+
2880
+ it ( 'should allow updating the dataFormat of a record' , async ( ) => {
2881
+ // alice writes a record with the data format set to text/plain
2882
+ const { status, record } = await dwnAlice . records . write ( {
2883
+ data : 'Hello, world!' ,
2884
+ message : {
2885
+ protocol : protocolDefinition . protocol ,
2886
+ protocolPath : 'thread' ,
2887
+ schema : protocolDefinition . types . thread . schema ,
2888
+ dataFormat : 'text/plain'
2889
+ }
2890
+ } ) ;
2891
+
2892
+ expect ( status . code ) . to . equal ( 202 ) ;
2893
+ expect ( record ) . to . not . be . undefined ;
2894
+ expect ( record . dataFormat ) . to . equal ( 'text/plain' ) ;
2895
+ expect ( await record . data . text ( ) ) . to . equal ( 'Hello, world!' ) ;
2896
+
2897
+ // update the record to JSON
2898
+ const updateResult = await record ! . update ( { dataFormat : 'application/json' , data : { subject : 'some subject' , body : 'some body' } } ) ;
2899
+ expect ( updateResult . status . code ) . to . equal ( 202 ) ;
2900
+ expect ( record . dataFormat ) . to . equal ( 'application/json' ) ;
2901
+ expect ( await record . data . json ( ) ) . to . deep . equal ( { subject : 'some subject' , body : 'some body' } ) ;
2902
+
2903
+ // update again without changing the dataFormat
2904
+ const updateResult2 = await record ! . update ( { data : { subject : 'another subject' , body : 'another body' } } ) ;
2905
+ expect ( updateResult2 . status . code ) . to . equal ( 202 ) ;
2906
+ expect ( record . dataFormat ) . to . equal ( 'application/json' ) ;
2907
+ expect ( await record . data . json ( ) ) . to . deep . equal ( { subject : 'another subject' , body : 'another body' } ) ;
2908
+ } ) ;
2879
2909
} ) ;
2880
2910
2881
2911
describe ( 'delete()' , ( ) => {
0 commit comments