-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): Add cache layer to test tokens
Add token cache layer Add more tests Add account tests add more tests
- Loading branch information
Showing
28 changed files
with
548 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
import type { Cache } from './cache'; | ||
|
||
export class CacheFs<T> implements Cache<T> { | ||
private readonly dir = 'node_modules/.cache/tokens'; | ||
|
||
set(value: T): void { | ||
if (!fs.existsSync(this.dir)) { | ||
fs.mkdirSync(this.dir, { recursive: true }); | ||
} | ||
|
||
fs.writeFileSync( | ||
path.join(this.dir, `${Date.now()}.json`), | ||
JSON.stringify(value), | ||
); | ||
} | ||
|
||
getAll(): T[] { | ||
if (!fs.existsSync(this.dir)) { | ||
fs.mkdirSync(this.dir, { recursive: true }); | ||
} | ||
|
||
const files = fs | ||
.readdirSync(this.dir) | ||
.filter((file) => file.endsWith('.json')) | ||
.map((file) => path.join(this.dir, file)); | ||
|
||
const entries = []; | ||
|
||
for (const file of files) { | ||
const entry = fs.readFileSync(file, 'utf8'); | ||
const parsed = JSON.parse(entry); | ||
entries.push(parsed); | ||
} | ||
|
||
return entries; | ||
} | ||
} |
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,4 @@ | ||
export interface Cache<T> { | ||
set(value: T): void; | ||
getAll(): T[]; | ||
} |
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,2 @@ | ||
export * from './cache'; | ||
export * from './cache-fs'; |
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 was deleted.
Oops, something went wrong.
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,2 @@ | ||
export * from './tootctl'; | ||
export * from './tootctl-docker'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
describe('announcements', () => { | ||
test.todo('lists announcements'); | ||
test.todo('dismisses announcement'); | ||
test.todo('adds a reaction'); | ||
test.todo('removes a reaction'); | ||
}); |
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,20 @@ | ||
describe('apps', () => { | ||
it('creates an app', () => { | ||
return clients.use(async (client) => { | ||
const app = await client.v1.apps.create({ | ||
clientName: 'My App', | ||
redirectUris: 'https://example.com/oauth/callback', | ||
scopes: 'read write', | ||
}); | ||
|
||
expect(app.name).toBe('My App'); | ||
}); | ||
}); | ||
|
||
it('verifies an app', () => { | ||
return clients.use(async (client) => { | ||
const app = await client.v1.apps.verifyCredentials(); | ||
expect(app.name).toEqual(expect.any(String)); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.