Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
add tests

Update ParseSession.js

Update ci.yml
  • Loading branch information
dblythy committed Aug 10, 2023
1 parent 41a41b4 commit b59b111
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: npm ci
# - name: Build types (enable when full typescript support)
# run: npm run build:types
- name: Check types
run: npm run test:types
build:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
"lib/",
"LICENSE",
"NOTICE",
"README.md"
"README.md",
"types/index.d.ts"
],
"browser": {
"react-native": false
},
"types": "types",
"dependencies": {
"@babel/runtime-corejs3": "7.22.6",
"idb-keyval": "6.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/ParseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ class ParseQuery {
* @param {string} modifiers The regular expression mode.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
startsWith(key: string, prefix: string, modifiers: string): ParseQuery {
startsWith(key: string, prefix: string, modifiers?: string): ParseQuery {
if (typeof prefix !== 'string') {
throw new Error('The value being searched for must be a string.');
}
Expand Down
2 changes: 0 additions & 2 deletions src/ParseSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import CoreManager from './CoreManager';
import isRevocableSession from './isRevocableSession';
import ParseObject from './ParseObject';
import ParseUser from './ParseUser';

import type { AttributeMap } from './ObjectStateMutations';
import type { RequestOptions, FullOptions } from './RESTController';

/**
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"allowJs": false
},
"files": [
"src/Parse.ts",
"src/ParseSession.ts"
"src/Parse.ts"
]
}
8 changes: 4 additions & 4 deletions types/ParseObject.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ declare class ParseObject {
* The only supported option is <code>error</code>.
* @returns {(ParseObject|boolean)} true if the set succeeded.
*/
set(key: mixed, value: mixed, options?: mixed): ParseObject | boolean;
set(key: mixed, value?: mixed, options?: mixed): ParseObject | boolean;
/**
* Remove an attribute from the model. This is a noop if the attribute doesn't
* exist.
Expand Down Expand Up @@ -783,7 +783,7 @@ declare class ParseObject {
* @returns {Promise} A promise that is fulfilled when the fetch
* completes.
*/
fetchWithInclude(keys: String | Array<string | Array<string>>, options: RequestOptions): Promise<any>;
fetchWithInclude(keys: String | Array<string | Array<string>>, options?: RequestOptions): Promise<any>;
/**
* Saves this object to the server at some unspecified time in the future,
* even if Parse is currently inaccessible.
Expand Down Expand Up @@ -873,8 +873,8 @@ declare class ParseObject {
* completes.
*/
save(arg1?: string | {
[attr: string]: mixed;
}, arg2?: SaveOptions | mixed, arg3?: SaveOptions): Promise<any>;
[attr: string]: object;
} | null, arg2?: SaveOptions | object, arg3?: SaveOptions): Promise<any>;
/**
* Deletes this object from the server at some unspecified time in the future,
* even if Parse is currently inaccessible.
Expand Down
144 changes: 72 additions & 72 deletions types/tests.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
import Parse from './Parse';
// Parse is a global type, but it can also be imported

// class GameScore extends Parse.Object {
// constructor(options?: any) {
// super('GameScore', options);
// }
// }
class GameScore extends Parse.Object {
constructor(options?: any) {
super('GameScore', options);
}
}

// class Game extends Parse.Object {
// constructor(options?: any) {
// super('Game', options);
// }
// }
class Game extends Parse.Object {
constructor(options?: any) {
super('Game', options);
}
}

// function test_config() {
// Parse.Config.save({ foo: 'bar' }, { foo: true });
// Parse.Config.get({ useMasterKey: true });
// }
function test_config() {
Parse.Config.save({ foo: 'bar' }, { foo: true });
Parse.Config.get({ useMasterKey: true });
}

// function test_object() {
// const game = new Game();
// game.save(null, {
// useMasterKey: true,
// sessionToken: 'sometoken',
// cascadeSave: false,
// }).then(result => result);
function test_object() {
const game = new Game();
game.save(null, {
useMasterKey: true,
sessionToken: 'sometoken',
cascadeSave: false,
}).then(result => result);

// if (!game.isNew()) {
if (!game.isNew()) {

// }
}

// if (game.toPointer().className !== 'Game') {
if (game.toPointer().className !== 'Game') {

// }
}

// game.fetch({});
game.fetch({});

// // Create a new instance of that class.
// const gameScore = new GameScore();
// Create a new instance of that class.
const gameScore = new GameScore();

// gameScore.set('score', 1337);
// gameScore.set('playerName', 'Sean Plott');
// gameScore.set('cheatMode', false);
gameScore.set('score', 1337);
gameScore.set('playerName', 'Sean Plott');
gameScore.set('cheatMode', false);

// // Setting attrs using object
// gameScore.set({
// level: '10',
// difficult: 15,
// });
// Setting attrs using object
gameScore.set({
level: '10',
difficult: 15,
});

// const score = gameScore.get('score');
// const playerName = gameScore.get('playerName');
// const cheatMode = gameScore.get('cheatMode');
const score = gameScore.get('score');
const playerName = gameScore.get('playerName');
const cheatMode = gameScore.get('cheatMode');

// gameScore.increment('score');
// gameScore.addUnique('skills', 'flying');
// gameScore.addUnique('skills', 'kungfu');
// gameScore.addAll('skills', ['kungfu']);
// gameScore.addAllUnique('skills', ['kungfu']);
// gameScore.remove('skills', 'flying');
// gameScore.removeAll('skills', ['kungFu']);
// game.set('gameScore', gameScore);
gameScore.increment('score');
gameScore.addUnique('skills', 'flying');
gameScore.addUnique('skills', 'kungfu');
gameScore.addAll('skills', ['kungfu']);
gameScore.addAllUnique('skills', ['kungfu']);
gameScore.remove('skills', 'flying');
gameScore.removeAll('skills', ['kungFu']);
game.set('gameScore', gameScore);

// const gameCopy = Game.fromJSON(JSON.parse(JSON.stringify(game)), true);
const gameCopy = Game.fromJSON(JSON.parse(JSON.stringify(game)), true);

// const object = new Parse.Object('TestObject');
// object.equals(gameScore);
// object.fetchWithInclude(['key1', 'key2']);
// }
const object = new Parse.Object('TestObject');
object.equals(gameScore);
object.fetchWithInclude(['key1', 'key2']);
}

// function test_errors() {
// try {
// throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'sdfds');
// } catch (error) {
// if (error.code !== 1) {
function test_errors() {
try {
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'sdfds');
} catch (error) {
if (error.code !== 1) {

// }
// }
// }
}
}
}

// function test_query() {
// const gameScore = new GameScore();
Expand Down Expand Up @@ -2053,21 +2053,21 @@ import Parse from './Parse';
// }
// }

function testSession() {
function testConstructor() {
// $ExpectType ParseSession
new Parse.Session();
// function testSession() {
// function testConstructor() {
// // $ExpectType ParseSession
// new Parse.Session();

// $ExpectType ParseSession
new Parse.Session({ example: 100 });
// // $ExpectType ParseSession
// new Parse.Session({ example: 100 });

// @ts-expect-error
new Parse.Session<{ example: number }>();
// // @ts-expect-error
// new Parse.Session<{ example: number }>();

// @ts-expect-error
new Parse.Session<{ example: number }>({ example: 'hello' });
}
}
// // @ts-expect-error
// new Parse.Session<{ example: number }>({ example: 'hello' });
// }
// }

// function testUser() {
// function testConstructor() {
Expand Down

0 comments on commit b59b111

Please sign in to comment.