@@ -30,122 +30,113 @@ void main() {
3030 ParseCoreData ().sessionId = previousSessionId;
3131 });
3232
33- test (
34- 'when a save() response carries a sessionToken different from the '
35- 'one sent, the SDK installs it as the global session token. Parse '
36- 'Server mints a fresh session when password is set on an existing '
37- '_User; the prior session is destroyed server-side, so the global '
38- 'session must be updated or subsequent requests fail with '
39- 'invalidSessionToken' ,
40- () async {
41- ParseCoreData ().setSessionId ('r:priorSession' );
42-
43- final ParseUser user = ParseUser (null , null , null , client: client);
44- user.fromJson (< String , dynamic > {
45- keyVarObjectId: userObjectId,
46- keyVarSessionToken: 'r:priorSession' ,
47- keyVarUsername: 'alice@example.com' ,
48- });
49-
50- when (
51- client.put (
52- putPath,
53- options: anyNamed ('options' ),
54- data: anyNamed ('data' ),
55- ),
56- ).thenAnswer (
57- (_) async => ParseNetworkResponse (
58- statusCode: 200 ,
59- data: jsonEncode (< String , dynamic > {
60- keyVarUpdatedAt: '2026-04-28T12:00:01.000Z' ,
61- keyVarSessionToken: 'r:freshSession' ,
62- }),
63- ),
64- );
65-
66- user.password = 'hunter2' ;
67-
68- final ParseResponse response = await user.save ();
69-
70- expect (response.success, isTrue);
71- expect (ParseCoreData ().sessionId, equals ('r:freshSession' ));
72- },
73- );
74-
75- test (
76- 'when a save() response does NOT carry a sessionToken, the global '
77- 'session is left untouched. the previously-cached local sessionToken '
78- 'on the user object must not be re-promoted to global state' ,
79- () async {
80- ParseCoreData ().setSessionId ('r:stableSession' );
81-
82- final ParseUser user = ParseUser (null , null , null , client: client);
83- user.fromJson (< String , dynamic > {
84- keyVarObjectId: userObjectId,
85- keyVarSessionToken: 'r:stableSession' ,
86- keyVarUsername: 'alice@example.com' ,
87- });
88-
89- when (
90- client.put (
91- putPath,
92- options: anyNamed ('options' ),
93- data: anyNamed ('data' ),
94- ),
95- ).thenAnswer (
96- (_) async => ParseNetworkResponse (
97- statusCode: 200 ,
98- data: jsonEncode (< String , dynamic > {
99- keyVarUpdatedAt: '2026-04-28T12:00:01.000Z' ,
100- }),
101- ),
102- );
103-
104- user.set <String >('localeIdentifier' , 'en-US' );
105-
106- await user.save ();
107-
108- expect (ParseCoreData ().sessionId, equals ('r:stableSession' ));
109- },
110- );
111-
112- test (
113- 'update() adopts a new sessionToken from the response. save() and '
114- 'update() are independent entry points, both need to install the '
115- 'token to keep the active session in sync with the server' ,
116- () async {
117- ParseCoreData ().setSessionId ('r:priorSession' );
118-
119- final ParseUser user = ParseUser (null , null , null , client: client);
120- user.fromJson (< String , dynamic > {
121- keyVarObjectId: userObjectId,
122- keyVarSessionToken: 'r:priorSession' ,
123- keyVarUsername: 'alice@example.com' ,
124- });
125-
126- when (
127- client.put (
128- putPath,
129- options: anyNamed ('options' ),
130- data: anyNamed ('data' ),
131- ),
132- ).thenAnswer (
133- (_) async => ParseNetworkResponse (
134- statusCode: 200 ,
135- data: jsonEncode (< String , dynamic > {
136- keyVarUpdatedAt: '2026-04-28T12:00:01.000Z' ,
137- keyVarSessionToken: 'r:freshSession' ,
138- }),
139- ),
140- );
141-
142- user.password = 'hunter2' ;
143-
144- final ParseResponse response = await user.update ();
145-
146- expect (response.success, isTrue);
147- expect (ParseCoreData ().sessionId, equals ('r:freshSession' ));
148- },
149- );
33+ test ('when a save() response carries a sessionToken different from the '
34+ 'one sent, the SDK installs it as the global session token. Parse '
35+ 'Server mints a fresh session when password is set on an existing '
36+ '_User; the prior session is destroyed server-side, so the global '
37+ 'session must be updated or subsequent requests fail with '
38+ 'invalidSessionToken' , () async {
39+ ParseCoreData ().setSessionId ('r:priorSession' );
40+
41+ final ParseUser user = ParseUser (null , null , null , client: client);
42+ user.fromJson (< String , dynamic > {
43+ keyVarObjectId: userObjectId,
44+ keyVarSessionToken: 'r:priorSession' ,
45+ keyVarUsername: 'alice@example.com' ,
46+ });
47+
48+ when (
49+ client.put (
50+ putPath,
51+ options: anyNamed ('options' ),
52+ data: anyNamed ('data' ),
53+ ),
54+ ).thenAnswer (
55+ (_) async => ParseNetworkResponse (
56+ statusCode: 200 ,
57+ data: jsonEncode (< String , dynamic > {
58+ keyVarUpdatedAt: '2026-04-28T12:00:01.000Z' ,
59+ keyVarSessionToken: 'r:freshSession' ,
60+ }),
61+ ),
62+ );
63+
64+ user.password = 'hunter2' ;
65+
66+ final ParseResponse response = await user.save ();
67+
68+ expect (response.success, isTrue);
69+ expect (ParseCoreData ().sessionId, equals ('r:freshSession' ));
70+ });
71+
72+ test ('when a save() response does NOT carry a sessionToken, the global '
73+ 'session is left untouched. the previously-cached local sessionToken '
74+ 'on the user object must not be re-promoted to global state' , () async {
75+ ParseCoreData ().setSessionId ('r:stableSession' );
76+
77+ final ParseUser user = ParseUser (null , null , null , client: client);
78+ user.fromJson (< String , dynamic > {
79+ keyVarObjectId: userObjectId,
80+ keyVarSessionToken: 'r:stableSession' ,
81+ keyVarUsername: 'alice@example.com' ,
82+ });
83+
84+ when (
85+ client.put (
86+ putPath,
87+ options: anyNamed ('options' ),
88+ data: anyNamed ('data' ),
89+ ),
90+ ).thenAnswer (
91+ (_) async => ParseNetworkResponse (
92+ statusCode: 200 ,
93+ data: jsonEncode (< String , dynamic > {
94+ keyVarUpdatedAt: '2026-04-28T12:00:01.000Z' ,
95+ }),
96+ ),
97+ );
98+
99+ user.set <String >('localeIdentifier' , 'en-US' );
100+
101+ await user.save ();
102+
103+ expect (ParseCoreData ().sessionId, equals ('r:stableSession' ));
104+ });
105+
106+ test ('update() adopts a new sessionToken from the response. save() and '
107+ 'update() are independent entry points, both need to install the '
108+ 'token to keep the active session in sync with the server' , () async {
109+ ParseCoreData ().setSessionId ('r:priorSession' );
110+
111+ final ParseUser user = ParseUser (null , null , null , client: client);
112+ user.fromJson (< String , dynamic > {
113+ keyVarObjectId: userObjectId,
114+ keyVarSessionToken: 'r:priorSession' ,
115+ keyVarUsername: 'alice@example.com' ,
116+ });
117+
118+ when (
119+ client.put (
120+ putPath,
121+ options: anyNamed ('options' ),
122+ data: anyNamed ('data' ),
123+ ),
124+ ).thenAnswer (
125+ (_) async => ParseNetworkResponse (
126+ statusCode: 200 ,
127+ data: jsonEncode (< String , dynamic > {
128+ keyVarUpdatedAt: '2026-04-28T12:00:01.000Z' ,
129+ keyVarSessionToken: 'r:freshSession' ,
130+ }),
131+ ),
132+ );
133+
134+ user.password = 'hunter2' ;
135+
136+ final ParseResponse response = await user.update ();
137+
138+ expect (response.success, isTrue);
139+ expect (ParseCoreData ().sessionId, equals ('r:freshSession' ));
140+ });
150141 });
151142}
0 commit comments