Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: fake roc v2 api #1

Merged
merged 51 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
95a83c3
wip: fake roc v2 api
stropitek Sep 19, 2018
11e3614
use generic type in abstract classes
stropitek Sep 20, 2018
128ef58
fake implementation of create
stropitek Sep 20, 2018
5139b3f
test content update
stropitek Sep 21, 2018
523e4e2
toJSON
stropitek Sep 21, 2018
9d6a76a
fake addGroups
stropitek Sep 21, 2018
aa4c191
check group unicity
stropitek Sep 22, 2018
0e00de0
fix fake rev incrementation
stropitek Oct 3, 2018
9278b7c
use prepare instead of prepublishOnly
stropitek Oct 3, 2018
1a3d4cb
reorganize tests
stropitek Oct 5, 2018
a3cdc0d
chore: use cheminfo tslint config
stropitek Oct 5, 2018
9c65380
fake query api
stropitek Oct 5, 2018
7c1e70d
update jest dependencies
stropitek Oct 6, 2018
3b21eb0
basic support of fake query and saving new attachments
stropitek Oct 9, 2018
f3c63e6
add fetchAttachment method to fake doc
stropitek Oct 9, 2018
3f55564
implement fake remove attachment
stropitek Oct 9, 2018
2983d5c
fix typescript problems
stropitek Oct 9, 2018
63fa558
add getAttachmentList and getAttachment methods to roc document
stropitek Oct 19, 2018
c99e4c7
throw when on fetch when query does not exist
stropitek Oct 19, 2018
8394ceb
fix: correctly copy attachments
targos Oct 25, 2018
5d2673a
return more info with getUser
stropitek Oct 26, 2018
1d04623
make FakeRoc compatible with BaseRoc
targos Oct 26, 2018
08f9327
rename IRocData to IFakeRocData
targos Oct 26, 2018
d4c96b2
let TS infer fake return types
targos Oct 26, 2018
7b1e951
implement skeleton for real API
targos Oct 26, 2018
3c8fc27
implement roc.getDocument
targos Oct 26, 2018
f264af3
getDocument shouldn't be async
targos Oct 26, 2018
9df60fe
fix fetch entry
targos Oct 26, 2018
24efcad
really fix fetch
targos Oct 26, 2018
d0e9e12
add getReducer
stropitek Oct 27, 2018
fb0d4fd
feat: implement update in real
stropitek Nov 1, 2018
6dfcbe7
simplify axios update request
stropitek Nov 2, 2018
d3c9911
remove superfluous axios option
stropitek Nov 2, 2018
abe8152
remove superfluous call to Array.from
stropitek Nov 2, 2018
278b5df
add real Query
stropitek Nov 2, 2018
504bcf1
feat: getReduceQuery
stropitek Nov 3, 2018
3268594
feat: make Query and ReduceQuery thenable
stropitek Nov 3, 2018
d4c3f17
refactor: export types from types.ts
stropitek Nov 3, 2018
950bdfb
fix: fix and cleanup types
stropitek Nov 3, 2018
1177384
refactor: one abstract class per file
stropitek Nov 3, 2018
e36a893
feat: get attachment list for real api
stropitek Nov 3, 2018
b1282fe
feat: implement fetchAttachment and export types in index file
stropitek Nov 3, 2018
21b5676
response type can be buffer
stropitek Nov 3, 2018
b0b873c
export all from index
stropitek Nov 3, 2018
a47a77f
feat: allow base options for reduce query
stropitek Nov 3, 2018
20083d8
fix: Query thenable should resolve with value not with promise
stropitek Nov 3, 2018
5f40837
fix: fix type in BaseRocDocument
stropitek Nov 9, 2018
d7e033a
implement create on real roc
stropitek Nov 16, 2018
608d02c
fix: use custom parameter serializer
stropitek Nov 17, 2018
79d8f37
fix: correct url when in roc.create
stropitek Nov 17, 2018
32f2383
update dependencies
targos Mar 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/RocBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export abstract class BaseRocDocument<RocType> {
newAttachments?: INewAttachment[],
deleteAttachments?: string[]
): Promise<IDocument>;
public abstract addGroups(groups: string | string[]): string[];
public abstract addGroups(groups: string | string[]): Promise<string[]>;

public getValue() {
return this.value;
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('fake roc', () => {
$content: {
test: 42
},
$owner: ['group1', 'group2']
$owner: ['group1', 'group2', 'group1']
};
const document = await roc.create(newDoc);
expect(document.getValue().$content).toEqual({ test: 42 });
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('fake roc', () => {
const data = getData();
const roc = new FakeRoc(data);
const doc = await roc.getDocument('uuid1');
const groups = await doc.addGroups(['group1', 'group2']);
const groups = await doc.addGroups(['group1', 'group2', 'group1']);
expect(groups).toEqual(['test@test.com', 'group1', 'group2']);
expect(doc.getValue().$owner).toEqual([
'test@test.com',
Expand Down
10 changes: 6 additions & 4 deletions src/fake/Roc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ export class FakeDocument extends BaseRocDocument<FakeRoc> {

this.checkConflict();
const doc = this.value!;
const owners = new Set(doc.$owner);
if (typeof groups === 'string') {
doc.$owner.push(groups);
owners.add(groups);
} else {
doc.$owner = doc.$owner.concat(groups);
groups.forEach(group => owners.add(group));
}
return doc.$owner;
doc.$owner = Array.from(owners);
return doc.$owner.slice();
stropitek marked this conversation as resolved.
Show resolved Hide resolved
}

private checkConflict() {
Expand Down Expand Up @@ -122,7 +124,7 @@ export class FakeRoc extends BaseRoc<FakeDocument> {
_rev: rev,
$modificationDate: Date.now(),
$creationDate: Date.now(),
$owner: ['test@test.com', ...newDocument.$owner]
$owner: ['test@test.com', ...Array.from(new Set(newDocument.$owner))]
stropitek marked this conversation as resolved.
Show resolved Hide resolved
};
if (!this.data[uuid]) {
this.data[uuid] = [];
Expand Down