-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73e9343
commit 6b1db05
Showing
16 changed files
with
133 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function randomString(length: number = 10): string { | ||
return Math.random() | ||
.toString(36) | ||
.substring(2, 2 + length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Express } from 'express'; | ||
import request = require('supertest'); | ||
import { DocumentResource, ResourceInputModel, ResourceType } from '@notespace/shared/src/workspace/types/resource'; | ||
|
||
export function documentRequests(app: Express) { | ||
async function createDocument(wid: string, name?: string): Promise<string> { | ||
const resource: ResourceInputModel = { | ||
name: name || 'Untitled', | ||
type: ResourceType.DOCUMENT, | ||
parent: undefined, | ||
}; | ||
const response = await request(app).post(`/workspaces/${wid}`).send(resource); | ||
expect(response.status).toBe(201); | ||
return response.body.id; | ||
} | ||
|
||
async function getDocument(wid: string, id: string): Promise<DocumentResource> { | ||
const response = await request(app).get(`/workspaces/${wid}/${id}`); | ||
expect(response.status).toBe(200); | ||
if (response.body.type !== ResourceType.DOCUMENT) throw new Error('Resource is not a document'); | ||
return response.body; | ||
} | ||
|
||
async function updateDocument(wid: string, id: string, name: string) { | ||
const response = await request(app).put(`/workspaces/${wid}/${id}`).send({ name }); | ||
expect(response.status).toBe(204); | ||
} | ||
|
||
async function deleteDocument(wid: string, id: string) { | ||
const response = await request(app).delete(`/workspaces/${wid}/${id}`); | ||
expect(response.status).toBe(204); | ||
} | ||
|
||
return { createDocument, getDocument, updateDocument, deleteDocument }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Express } from 'express'; | ||
import { documentRequests } from './documentRequests'; | ||
import { workspaceRequests } from './workspaceRequests'; | ||
|
||
export function requests(app: Express) { | ||
return { | ||
document: documentRequests(app), | ||
workspace: workspaceRequests(app), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Express } from 'express'; | ||
import request = require('supertest'); | ||
import { WorkspaceMetaData } from '@notespace/shared/src/workspace/types/workspace'; | ||
|
||
export function workspaceRequests(app: Express) { | ||
async function createWorkspace(name: string): Promise<string> { | ||
const response = await request(app).post('/workspaces').send({ name }); | ||
expect(response.status).toBe(201); | ||
return response.body.id; | ||
} | ||
|
||
async function getWorkspaces(): Promise<WorkspaceMetaData[]> { | ||
const response = await request(app).get('/workspaces'); | ||
expect(response.status).toBe(200); | ||
return response.body; | ||
} | ||
|
||
async function getWorkspace(id: string, metaOnly: boolean): Promise<WorkspaceMetaData> { | ||
const response = await request(app).get(`/workspaces/${id}?metaOnly=${metaOnly}`); | ||
expect(response.status).toBe(200); | ||
return response.body; | ||
} | ||
|
||
async function updateWorkspace(id: string, name: string) { | ||
const response = await request(app).put(`/workspaces/${id}`).send({ name }); | ||
expect(response.status).toBe(204); | ||
} | ||
|
||
async function deleteWorkspace(id: string) { | ||
const response = await request(app).delete(`/workspaces/${id}`); | ||
expect(response.status).toBe(204); | ||
} | ||
|
||
return { createWorkspace, getWorkspaces, getWorkspace, updateWorkspace, deleteWorkspace }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters