Repository: parse-community/Parse-SDK-JS (JavaScript)

Issue:
AddField with type date and default value not working
### New Issue Checklist
<!--
    Check every following box [x] before submitting your issue.
    Click the "Preview" tab for better readability.
    Thanks for contributing to Parse Platform!
-->

- [x] I am not disclosing a [vulnerability](https://github.com/parse-community/parse-server/blob/master/SECURITY.md).
- [x] I am not just asking a [question](https://github.com/parse-community/.github/blob/master/SUPPORT.md).
- [x] I have searched through [existing issues](https://github.com/parse-community/Parse-SDK-JS/issues?q=is%3Aissue).
- [x] I can reproduce the issue with the latest versions of [Parse Server](https://github.com/parse-community/parse-server/releases) and the [Parse JS SDK](https://github.com/parse-community/Parse-SDK-JS/releases). <!-- We don't investigate issues for outdated releases. -->

### Issue Description
<!-- What is the specific issue? -->
When adding a new field with type `Date` and with `defaultValue` it complains that the `defaultValue` should be with type date.

### Steps to reproduce
<!-- How can someone else reproduce the issue? -->
```


    const newLocalSchema = new Parse.Schema('BlaSchema')
    newLocalSchema.addField('bla', 'Date', { defaultValue: new Date() })
    await newLocalSchema.save()


```
### Actual Outcome
<!-- What outcome, for example query result, did you get? -->
```
error: Parse error:  schema mismatch for BlaSchema.bla default value; expected Date but got String {"code":111,"stack":"Error: schema mismatch for BlaSchema.bla default value; expected Date but got String\n    at SchemaController.addClassIfNotExists
```
![image](https://user-images.githubusercontent.com/14947957/137818537-c9f99328-9acb-4ded-866d-d30435e0adf0.png)

### Expected Outcome
<!-- What outcome, for example query result, did you expect? -->
It should work.

###  Environment
<!-- Be specific with versions, don't use "latest" or semver ranges like "~x.y.z" or "^x.y.z". -->

Server
- Parse Server version: `^4.10.2`
- Operating system: `Windows`
- Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): `local`

Database
- System (MongoDB or Postgres): `Mongo`
- Database version: `v5.0.2`
- Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): `docker`

Client
- Parse JS SDK version: `3.3.0`

### Logs
<!-- Include relevant logs here. Turn on additional logging by configuring VERBOSE=1 in your environment. -->



Discussion:

### Thanks for opening this issue!

- 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our [Contribution Guide](https://github.com/parse-community/parse-server/blob/master/CONTRIBUTING.md) for how to make a pull request, or read our [New Contributor's Guide](https://blog.parseplatform.org/learn/tutorial/community/nodejs/2021/02/14/How-to-start-contributing-to-Parse-Server.html) if this is your first time contributing.

<!-- parse-issue-bot-meta-tag-id {"suggestPr":true,"thanksFeature":false,"thanksPr":false} -->


Not sure whether this is a Parse JS SDK issue, from the logs it looks like a Parse Server issue. I'm transferring the issue to the server repository. Could you open a PR with a failing test?
![image](https://user-images.githubusercontent.com/92439533/162271531-323e34c6-b855-4bd7-97a9-68633b2903a5.png)

Please reference above content!
Thank you
@mtrezza after some tedious debugging I can confirm this is an SDK issue.

`addDate('fieldName', {defaultValue})` works
`addField('fieldName', 'Date', {defaultValue})` does not work

It will be a simple fix once transferred



Patch:
diff --git a/src/ParseSchema.js b/src/ParseSchema.js
index 49c717f0d..16174c8d6 100644
--- a/src/ParseSchema.js
+++ b/src/ParseSchema.js
@@ -241,6 +241,14 @@ class ParseSchema {
     if (options.defaultValue !== undefined) {
       fieldOptions.defaultValue = options.defaultValue;
     }
+    if (type === 'Date') {
+      if (options && options.defaultValue) {
+        fieldOptions.defaultValue = {
+          __type: 'Date',
+          iso: new Date(options.defaultValue),
+        };
+      }
+    }
     this._fields[name] = fieldOptions;
     return this;
   }
@@ -310,12 +318,6 @@ class ParseSchema {
    * @returns {Parse.Schema} Returns the schema, so you can chain this call.
    */
   addDate(name: string, options: FieldOptions) {
-    if (options && options.defaultValue) {
-      options.defaultValue = {
-        __type: 'Date',
-        iso: new Date(options.defaultValue),
-      };
-    }
     return this.addField(name, 'Date', options);
   }
 


Test patch:
diff --git a/src/__tests__/ParseSchema-test.js b/src/__tests__/ParseSchema-test.js
index 983c1a247..409ecb507 100644
--- a/src/__tests__/ParseSchema-test.js
+++ b/src/__tests__/ParseSchema-test.js
@@ -194,6 +194,15 @@ describe('ParseSchema', () => {
     }
   });
 
+  it('can add date field with default value', () => {
+    const schema = new ParseSchema('NewSchemaTest');
+    const date = new Date();
+    schema.addDate('testField', { defaultValue: date });
+    schema.addField('testField2', 'Date', { defaultValue: date });
+    expect(schema._fields.testField.defaultValue).toEqual({ __type: 'Date', iso: date });
+    expect(schema._fields.testField2.defaultValue).toEqual({ __type: 'Date', iso: date });
+  });
+
   it('cannot add index with null name', done => {
     try {
       const schema = new ParseSchema('SchemaTest');