-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: initiate async rest test using supertest
- Loading branch information
Ade Yahya Prasetyo
committed
Mar 17, 2021
1 parent
8c10e05
commit 263cd13
Showing
15 changed files
with
263 additions
and
11,257 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,3 +4,5 @@ node_modules/ | |
dist/ | ||
|
||
.autoenv.zsh | ||
yarn-error.log | ||
.cache |
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,68 @@ | ||
import os from 'os'; | ||
import path from 'path'; | ||
import fs from 'fs/promises'; | ||
import request from 'supertest'; | ||
import { Config } from '../src/types/config-combine'; | ||
import { runForTest } from '../src/express'; | ||
|
||
const config: Config = { | ||
rest: { | ||
sources: [ | ||
{ | ||
name: 'pokeapi', | ||
origin: 'https://pokeapi.co', | ||
transforms: { | ||
'/api/v2/berry/:id': { | ||
get: [ | ||
{ | ||
field: 'root.name', | ||
resolvers: [ | ||
{ | ||
faker: 'name.firstName', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const homeDir = os.homedir(); | ||
const cachePath = path.join(homeDir, '.warlock-cache'); | ||
|
||
describe('faker resolver 1', () => { | ||
beforeAll(() => { | ||
return Promise.all([fs.rmdir(cachePath, { recursive: true })]); | ||
}); | ||
|
||
const app = runForTest(config); | ||
|
||
it('(MOCKPUBAPI01) should response 200 and cache miss', (done) => { | ||
request(app) | ||
.get('/https://pokeapi.co/api/v2/berry/1') | ||
.expect(200) | ||
.end((err, res) => { | ||
if (err) return done(err); | ||
|
||
expect(res.headers['x-warlock-cache']).toBe('MISS'); | ||
expect(typeof res?.body?.firmness?.name).toBe('string'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('(MOCKPUBAPI02) should response 200 and cache hit', (done) => { | ||
request(app) | ||
.get('/https://pokeapi.co/api/v2/berry/1') | ||
.expect(200) | ||
.end((err, res) => { | ||
if (err) return done(err); | ||
|
||
expect(res.headers['x-warlock-cache']).toBe('HIT'); | ||
expect(typeof res?.body?.firmness?.name).toBe('string'); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,70 @@ | ||
import os from 'os'; | ||
import path from 'path'; | ||
import fs from 'fs/promises'; | ||
import request from 'supertest'; | ||
import { Config } from '../src/types/config-combine'; | ||
import { runForTest } from '../src/express'; | ||
|
||
const config: Config = { | ||
rest: { | ||
sources: [ | ||
{ | ||
name: 'pokeapi', | ||
origin: 'https://pokeapi.co', | ||
transforms: { | ||
'/api/v2/berry/:id': { | ||
get: [ | ||
{ | ||
field: 'root.name', | ||
resolvers: [ | ||
{ | ||
faker: 'name.firstName', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const homeDir = os.homedir(); | ||
const cachePath = path.join(homeDir, '.warlock-cache'); | ||
|
||
describe('faker resolver 1', () => { | ||
beforeAll(() => { | ||
return Promise.all([fs.rmdir(cachePath, { recursive: true })]); | ||
}); | ||
|
||
const app = runForTest(config); | ||
|
||
it('(MOCKPUBAPI04) should response 200 and cache miss', (done) => { | ||
request(app) | ||
.get('/https://pokeapi.co/api/v2/berry/1') | ||
.expect(200) | ||
.end((err, res) => { | ||
if (err) return done(err); | ||
|
||
expect(res.headers['x-warlock-cache']).toBe('MISS'); | ||
expect(res?.body?.firmness?.name !== 'cheri').toBe(true); | ||
expect(typeof res?.body?.firmness?.name).toBe('string'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('(MOCKPUBAPI05) should response 200 and cache hit', (done) => { | ||
request(app) | ||
.get('/https://pokeapi.co/api/v2/berry/1') | ||
.expect(200) | ||
.end((err, res) => { | ||
if (err) return done(err); | ||
|
||
expect(res.headers['x-warlock-cache']).toBe('HIT'); | ||
expect(res?.body?.firmness?.name !== 'cheri').toBe(true); | ||
expect(typeof res?.body?.firmness?.name).toBe('string'); | ||
done(); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.