Skip to content

Instantly share code, notes, and snippets.

@db
Created November 10, 2023 02:11
Show Gist options
  • Save db/dc3cdab96de90ed36b0bcbf81e352c54 to your computer and use it in GitHub Desktop.
Save db/dc3cdab96de90ed36b0bcbf81e352c54 to your computer and use it in GitHub Desktop.
resly job
{
"name": "resly",
"version": "1.0.0",
"main": "submitResume.js",
"type": "module",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"axios": "^1.6.1"
},
"devDependencies": {
"@babel/core": "^7.23.3",
"@babel/preset-env": "^7.23.3",
"babel-jest": "^29.7.0",
"jest": "^29.7.0"
},
"jest": {
"transform": {
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest"
},
"resetMocks": true,
"clearMocks": true,
"resetModules": true
},
"babel": {
"presets": ["@babel/preset-env"]
}
}
{
"redacted": true
}
import submitResume from './submitResume.js';
const isTestMode = process.argv.includes('--test');
submitResume(isTestMode)
.then(() => {
console.log('Finished submitting resume');
})
.catch(error => {
console.error('An error occurred:', error.message);
});
import axios from 'axios';
import fs from 'fs/promises';
const createFakeAdapter = () => config => {
console.log('URL:', config.url);
console.log('Params:', config.params);
console.log('Method:', config.method);
console.log('Data:', JSON.stringify(config.data, null, 2));
return Promise.resolve({
data: '--fake response data--',
status: 200,
statusText: 'OK',
headers: {},
config,
});
};
const readResumeFile = async (filePath) => {
const fileContents = await fs.readFile(filePath, 'utf8');
return JSON.parse(fileContents);
};
const submitResume = async (isTestMode = false, resumeData, filePath = 'resume.json') => {
const apiUrl = 'https://api.resly.com.au/career/jobs';
const params = new URLSearchParams({ name: 'Dean Burge' });
try {
const data = resumeData ?? await readResumeFile(filePath);
const axiosInstance = isTestMode
? axios.create({ adapter: createFakeAdapter() })
: axios;
const response = await axiosInstance.post(apiUrl, data, { params });
console.log('Resume submitted successfully:', response.data);
return response.data;
} catch (error) {
console.error('Error:', error.message);
throw error;
}
};
export default submitResume;
import axios from 'axios';
import submitResume from './submitResume.js';
jest.mock('axios');
jest.mock('fs', () => ({
promises: {
readFile: jest.fn(),
}
}));
describe('submitResume', () => {
it('sends resume data correctly in live mode', async () => {
const mockData = { name: 'Dean Burge' };
axios.post.mockResolvedValue({ data: 'success' });
await submitResume(false, mockData);
expect(axios.post).toHaveBeenCalledWith(
'https://api.resly.com.au/career/jobs',
mockData,
expect.anything(),
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment