jeudi 1 janvier 2015

How can I write a test for content that expires?

For example, suppose I have a REST API that create a voucher. The client would POST to:



/create/voucher


Then, to use a simplified example, a GET request to



/voucher/123456


would return



{amount: 100,
expired: false}


to represent a $100 voucher for client 123456 that hasn't expired. Let's say that the voucher should expire in 24 hours. At a conceptual level, how would I test this functionality? The 'manual' way to do it would be to have the test case sleep for 24 hours and then rerun the GET request. This obviously isn't feasible.


For what it's worth the language that I'm using is JavaScript. I can't think of any 'nice' ways to do this without doing something hacky like overwriting Date.getTime()


Aucun commentaire:

Enregistrer un commentaire